Repository navigation
fix(editor): draw a newly opened document tab on its first paint - #43
Closed
pythonlearner1025 wants to merge 1 commit into
Closed
pythonlearner1025 wants to merge 1 commit into
pythonlearner1025 wants to merge 1 commit into
Conversation
A newly opened tab showed an empty viewport until the user switched to another tab and back. The centre strip renders only the active tab panel, so every tab change mounts a new canvas container. The effect that moves viewer.container into it depended on the container ref's current value, which React reads during render, one commit behind. DocumentStore.open renders twice, once for the new tab and once for its activation, so the first render ran the effect as a no-op and the second read the same stale value and skipped it. The canvas stayed in the detached panel. A plain tab switch renders once, which is why switching away and back repaired it. Fix: a ref callback keyed on the viewer, so the mounted node itself reports its mount and the container moves on every mount. Verification: headless Chromium, three runs of four document kinds with a fresh session each: first paint blank 9 of 12 before, 3 of 12 after, and the remaining three are a material document that draws nothing before and after and on any tab, a separate bug. The new packages/kite3d/test/editor-open-tab.test.ts fails without the fix. npm test -w packages/kite3d 7 pass; typecheck, lint, build:editor pass. Evidence under ~/games/terminator-evidence/docs/evidence/kite3d-open-tab/. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
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.
What part this touches
The editor's centre area, in
packages/editor. The centre strip holds one tab per open document. The viewport is one three.js canvas, owned by the viewer, that the editor moves into whichever tab panel is active. The panel layout inWindowPanesLayout.tsxrenders only the active tab's panel, so every tab change unmounts the old panel and mounts a new, empty one.ThreeEditorComponent.tsxis the component that moves the canvas into the mounted panel.Documents live in
packages/editor/src/documents.DocumentStore.open(path)adds a tab for a file and then activates it. Each of those two steps triggers a React render.The bug
Reported by the owner: "newly opened tabs viewport remain empty until i switch to another viewport tab and then switch back to the newly opened one."
Step by step, measured in a headless run:
Proof of the mechanism, without a code change: after
open, one extra React render with no tab change put the canvas back. The script is in the evidence folder.The fix
useRefimport goes.The risk trade
open. It hides the timing instead of fixing it.Tests
packages/kite3d/test/editor-open-tab.test.tsdrives the Files panel double-click headless and asserts the canvas is mounted and drawn on the first paint. Without the fix it fails withexpected { mounted: false, drawn: false } to deeply equal { mounted: true, drawn: true }.npm test -w packages/kite3d: 7 pass.npm run typecheck,npm run lint,npm run build:editor: pass, re-run after the rebase onto the Resources tab commit.~/games/terminator-evidence/docs/evidence/kite3d-open-tab/.Deploy
The editor ships inside the
@kite3d/editorandkite3dpackages. Nothing ships until this lands onmainand a release runs.git checkout main && git pull npm run build npm run release:dry npm run releaseRollback: revert the squash commit on
main, rebuild, and release the next alpha.🤖 Generated with Claude Code