fix: guard Output page against stale async chart renders (#101) - #252
Open
Sanjay Singh (san360) wants to merge 1 commit into
Open
fix: guard Output page against stale async chart renders (#101)#252Sanjay Singh (san360) wants to merge 1 commit into
Sanjay Singh (san360) wants to merge 1 commit into
Conversation
- createChart() now bails out with a warning instead of crashing when its canvas isn't in the live DOM (Chart.js dereferences a null/undefined element and throws otherwise). - page-output.ts tracks a render generation counter; renderProductionTab and renderTokenUsageTab bail out after their await if a newer render (tab switch, range change, or re-navigation) has since started, so a slow response can no longer overwrite the current tab's DOM. Fixes intermittent 'Failed to render Output' error boundary crashes when switching pages/tabs/ranges while Output is still loading. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #101 — the Output page's intermittent
⚠️ Failed to render Output — Cannot read properties of undefined/null (reading …)error boundary crash.Root cause
createChart()insrc/webview/shared.tspasseddocument.getElementById(canvasId)straight intonew Chart(...)with no null check.renderOutput/renderProductionTab/renderTokenUsageTabinsrc/webview/page-output.tsrender a spinner,await rpc(...), then re-render tab markup and callcreateChart(...)— with no cancellation of stale in-flight renders across that async gap.If the user switched nav pages, toggled the Code Output ↔ Token Usage tab, or clicked date-range buttons rapidly while a request was still in flight, the stale promise would eventually resolve and either:
Fix (two layers, per the repro/fix notes in #101)
createChart(src/webview/shared.ts) — now checksdocument.getElementById(canvasId)fornulland returnsnullwith aconsole.warninstead of handing a null element tonew Chart(...). Return type updated toChart | null; no call site used the return value, so this is a safe, non-breaking change.page-output.ts— added a module-levelrenderGenerationcounter, bumped once per render attempt (initial mount, tab switch, or range change) inrenderActiveTab().renderProductionTab/renderTokenUsageTabcapture the generation at entry and bail out immediately after theirawait rpc(...)if a newer render has since started, so a slow/superseded response never touches the DOM again.Testing
Ran the full repo check suite from the worktree:
npm run typecheck✅npm run lint✅ (0 errors; pre-existing warnings only, none introduced)npm run spellcheck✅npm run knip✅npm test(vitest) — 1341 passed; 7 failures insrc/core/github-app-analytics.test.tsare pre-existing and unrelated (verified by stashing this change and re-running the same file — identical failures onmain).npm run build+npx playwright test(full e2e suite) — 37 passed, 7 skipped (pre-existing feature-flag gating), 0 failures, including all applicabletests/e2e/output.spec.tscases.Notes
createChart's newChart | nullreturn type doesn't affect any existing caller (none of the ~30 call sites across the webview capture the return value).