Frontend: PriceChartLightweightCanvas lifecycle tests (resize, stale init, early indicators) #225
Labels
No labels
agent:fix_bugfix
agent:fix_conflicts
agent:fix_security
agent:gap_analysis
agent:implement
agent:implement
agent:implement
agent:open_issues
agent:ready
agent:research
agent:security_audit
agent:verify
architecture
backend
blocker:hybrid
blocker:launch
blocker:limit-orders
blocker:v2
block:log_only
block:security
bug
ci
contracts
correctness
deploy
dev
devops
docs
documentation
duplicate
e2e
enhancement
epic
feature
frontend
functional-completion
gas
good first issue
governance
help wanted
high-risk
hooks
hybrid
indexer
infra
infrastructure
integrators
invalid
launch-blocker
limit-orders
localnet
localterra
low priority
missing-implementation
needs-design
ops
performance
priority
high
priority
medium
product
qa
QA
question
ready
ready
research
scripts
security
security-hardening
smartcontracts
tech-debt
testing
ux
UX
v2
verification
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
code/cl8y-dex-terraclassic#225
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Close regression gaps in
PriceChartLightweightCanvaslifecycle: post-layout sizing (applySize/ doublerequestAnimationFrame/ResizeObserver), stale async init when unmounting beforeimport('lightweight-charts')resolves, and indicator toggles whilechartModelReadyis still false. These paths are called out in GitLab #211 test plans but are not fully covered by the real-library Vitest suite or stub tests today.Bundled scope: post-layout resize · stale async init · indicator toggle before ready
Current codebase
frontend-dapp/src/components/charts/PriceChartLightweightCanvas.tsxchartInitIdRef— increments per effect run; stale inits callchart.remove()applySize()→chart.applyOptions({ width, height }); doublerAFafter mount;ResizeObserveron containeruseEffectruns only whenchartModelReady === truesetDataeffectuseEffectupdates series when refs exist (nochartModelReadygate)*.charts.test.{ts,tsx}vianpm run test:charts(#211) — mount/update/MA toggle; no resize/stale-init/early-indicator testsPriceChart.test.tsx— interval/pair (#148); no canvas lifecycleWhy this is needed
applySize+ doublerAF, production shows blank or clipped canvases while unit tests stay green.chartInitIdRefmust prevent orphan charts and React warnings — untested regression vector.syncPriceChartIndicatorOverlaysis gated onchartModelReady.Constraints and guardrails
npm run test:run; add real-library cases only innpm run test:chartswhere canvas/layout is required (#211).test.skipwithout a linked follow-up (#105).data-testidover canvas pixel assertions.Relevant files
frontend-dapp/src/components/charts/PriceChartLightweightCanvas.tsxfrontend-dapp/src/components/charts/priceChartLightweightIndicatorSync.tsfrontend-dapp/src/components/charts/priceChartPaneHeights.tsfrontend-dapp/src/components/charts/__tests__/PriceChartLightweightCanvas.charts.test.tsxfrontend-dapp/src/components/charts/__tests__/PriceChartLightweightCanvas.test.tsx(new stub contract — may overlap with bundled stub issue; coordinate)frontend-dapp/src/test/lightweightChartsJsdomMock.tsfrontend-dapp/vitest.config.charts.ts,src/test/chartsSetup.tsdocs/frontend.md,skills/AGENTS_FRONTEND_PRICE_CHART.mdRecommended direction
ResizeObserverandclientWidth/clientHeight; assertchart.applyOptions(or mock spy) receives width > 0 and height ≥ 320 after doublerAF. Optionaltest:chartscase with sized parent div.PriceChartLightweightCanvas.test.tsx, delay resolvedimport('lightweight-charts')viavi.mock+vi.doMock; unmount before resolve; expect no throw,chart.removeat most once for abandoned init, no duplicate canvases.showSma7/showRsibeforechartModelReady; assert no uncaught errors and correct state after ready (pane count / spy calls).Acceptance criteria
applyOptions(or equivalent) runs with positive dimensions after layout (doublerAFpath).removecount).chartModelReady— no throw; after ready, topology matches toggle state (#150).npm run test:runandnpm run test:chartsremain green.docs/frontend.md/skills/AGENTS_FRONTEND_PRICE_CHART.mdnote new regression tests (invariant #9 post-layout).Test plan — functional paths
width:0then layout to 640×400rAF, chart width/height > 0applySizeupdates height; volume pane height recalculatedshowRsitrue, resize parentrsiPaneHeightPximport()mockremove; nosetChartModelReady(true)for stale idremovePane(2)still works on offremovecount matches successful initsTest plan — attack vectors / failure modes
initIdsetschartModelReadyapplyOptionson removed chartVerification criteria
cd frontend-dapp && npm run test:run— new/updated stub tests pass.cd frontend-dapp && npm run test:charts— any new real-library layout tests pass./tradechart in narrow flex column — canvas fills plot after load (#151).Related issues
marked as related to #211
marked as related to #151
marked as related to #150
marked as related to #148
mentioned in commit
09d2544f26Implementation summary
Closed regression gaps for
PriceChartLightweightCanvaslifecycle (#225):Code & tests
PriceChartLightweightCanvas.test.tsx(defaultnpm run test:run): post-layoutapplyOptionsafter doublerequestAnimationFrame,ResizeObserverresize, unmount-before-import, React StrictMode single-chart init, unmountremove, indicator toggles beforechartModelReady(MA7 + RSI), rapid mount/unmount ×10.PriceChartLightweightCanvas.charts.test.tsx(npm run test:charts): real-library positive canvas dimensions after double rAF.priceChartLightweightModule.ts: thinloadPriceChartLightweightModule()wrapper so Vitest can defer dynamic import without affecting production behavior.lightweightChartsJsdomMock.ts: singleton chart spy,blockNextImport/releaseBlockedImport, trackingResizeObserver.Docs (cross-linked)
Merged to
mainin commit09d2544.Verification checklist
cd frontend-dapp && npm run test:run— includes newPriceChartLightweightCanvas.test.tsxcd frontend-dapp && npm run test:charts— includes post-layout canvas sizing case/trade: chart in a narrow flex column fills plot after load (#151)@brouie — please run through the checklist above when you have a moment. Leaving this issue open until verified.
mentioned in issue #227
Verification complete (agent,
verify/issue-225worktree)Verified GitLab #225 against
main@54a6346(worktree fast-forwarded fromorigin/main; no production code changes required).Automated checks — PASS
npm run test:run—PriceChartLightweightCanvas.test.tsxnpm run test:run— full suitenpm run test:charts—PriceChartLightweightCanvas.charts.test.tsxnpm run test:charts— full suiteAcceptance criteria mapping:
applyOptionswith positive dimensions after doublerequestAnimationFrame(stub + real-library)blockNextImport/ StrictMode single-chart)chartModelReady— MA7 + RSI; no throw; topology syncs after readydocs/frontend.md,docs/testing.md,skills/AGENTS_FRONTEND_PRICE_CHART.mdinvariants #9–#11)Manual checks — PASS
Local stack (indexer
:3001, LocalTerra LCD/RPC) — infra left running; frontend started on:5173for verification only, then stopped./trade— chart container 495×336 px in flex layout; child canvases width/height > 0 after load (#151)/trade→/poolwithin ~50 ms) — 0 detached chart canvases; noprice-chart-lightweight-canvasroot left in DOMFollow-up checklist (for spot re-check)
cd frontend-dapp && npm run test:run && npm run test:charts/tradein a narrow viewport — plot fills after loadAll issue-body verification criteria and comment checklist items pass. Closing.