Repository navigation
fix(shared): report the window size when useResize mounts - #2695
Open
Dev-next-gen wants to merge 1 commit into
Open
Dev-next-gen wants to merge 1 commit into
Dev-next-gen wants to merge 1 commit into
Conversation
resizeWindow only called its callback from the window resize listener, so useResize() without a container stayed at width 0 and height 0 until the window was resized. The ResizeObserver path already reports on observe; report the current window size on subscribe as well.
🦋 Changeset detectedLatest commit: a6c40b6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 8 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This branch has not been deployed
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.
Why
useResize()without acontainerreturnswidthandheightof 0 after mount, and they stay at 0 until the window fires aresizeevent.resizeWindowonly calls its callbacks from theresizelistener, so nothing measures the window whenuseResizesubscribes. TheResizeObserverpath doesn't have this problem because the observer reports once onobserve.Resolves #2694
What
resizeWindownow calls the new callback with the currentinnerWidth/innerHeightwhen it subscribes.useResizealready treats its first measurement as immediate, so the spring jumps to the window size on mount, and laterresizeevents animate as before.The tests in
useResize.animation.test.tsxused the first dispatchedresizeevent as the first measurement. With this change the first measurement happens on mount, somountnow stubs the initialinnerWidth/innerHeightand the tests cover the same cases from there. Onnext, three of them fail against the adaptedmount(expected +0 to be 100), which is the same bug.I added a test to
useResize.test.tsxthat mountsuseResize({})and checks the springs match the window size afteradvanceUntilIdle(). Onnextit fails withexpected +0 to be 414; with the fix, theuseResize,useScroll,onScrollandresizeElementtests all pass (14/14, Chromium).oxfmt --checkandoxlintare clean on the changed files.pnpm check:typesfails for me on module resolution in files this PR doesn't touch, because I didn't run a build first, so I'm leaving that to CI.Checklist
Resolves #…)pnpm format:check,pnpm lint,pnpm check:typesandpnpm test:unitpass locallyFound by a defect-hunting pipeline I build and run (Dev-next-gen), using Claude Code with Anthropic's Claude Opus 5.5.