Skip to content

Conversation

ali-idrizi
Copy link

@ali-idrizi ali-idrizi commented Oct 3, 2025

Before

In the useViewportSize hook, nothing is updating the size state after hydration is run. This was causing useViewport size to get stuck on 0x0 until the window is resized, just like in the screen recording below:

fix-use-viewport.mp4

After

The onResize function is run within the useEffect just as the resize listener is attached. I have written a test that fails without this call.

✅ Pull Request Checklist:

  • Included link to corresponding React Spectrum GitHub Issue.
  • Added/updated unit tests and storybook for this change (for new code or code which already has tests).
  • Filled out test instructions.
  • Updated documentation (if it already exists for this component).
  • Looked at the Accessibility Practices for this feature - Aria Practices

📝 Test Instructions:

🧢 Your Project:

@ali-idrizi
Copy link
Author

Given that onResize has a condition, and the update within useEffect should run unconditionally, I have extract the logic that updates the size state to a separate function, which now gets called instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant