Repository navigation
fix(dynamic-images): re-measure layers once the editor canvas is shown - #1828
Merged
Merged
Conversation
After Create, the client-side navigation to the Edit page mounted the canvas while the new page was still hidden (display: none). react-rnd measures each layer's offset from on-screen positions once, at mount, so it read 0 and stored an offset of -x: every layer was drawn at twice its saved x/y until the page was reloaded. The saved document was always correct. useShownLayoutVersion watches the canvas with a ResizeObserver and goes up when it turns from hidden to shown; the layers are keyed on it, so they remount and measure against the real layout. Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.
Problem
After creating a dynamic image, the app navigates to its Edit page. There, every layer was drawn away from where it was placed. After a reload (F5) the layers were back in the right place. The saved document was always correct; only the editor's drawing was off.
Cause
The Create → Edit client-side navigation mounts the editor while the new page is still inside a
display: noneancestor.react-rndmeasures each layer's offset from its parent once, at mount, from on-screen positions. Hidden elements report 0, so the offset becomes-x, and each layer is drawn at twice its savedx/y.Reproduced in Chrome: a text layer saved at (224, 144) was drawn at (448, 288) after the navigation. It was still there 2 s later, and back at (224, 144) after a reload. Instrumenting the first
getBoundingClientRecton the Edit page showed the hidden ancestor.Fix
useShownLayoutVersion(ref)(components/use-shown-layout-version.ts). AResizeObserverwatches the canvas, and a counter goes up whenever the canvas turns from hidden to shown.<Rnd>s are keyed on${element.id}:${layoutVersion}, so they remount and measure again against the real layout. A canvas that is visible from the start never remounts. The saved data is not touched.Verification
components/__tests__/use-shown-layout-version.test.tsx: hidden → shown, visible from start, hidden again → shown again, disconnect on unmount.pnpm lintand buildercheck-typespass.dynamic-image-form-locked.test.tsxstill passes.🤖 Generated with Claude Code