-
-
Notifications
You must be signed in to change notification settings - Fork 32.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Regression: withWidth fails on the server side because of useMediaQuery #16184
Comments
@fzaninotto If you are mounting the components, you need the browser API to be available. It seems that JSDOM doesn't implement it yet: https://github.com/jsdom/jsdom/blob/94774014e2244730f24d1fcb8c40d8fee3ea6b75/test/web-platform-tests/to-upstream/html/browsers/the-window-object/window-properties-dont-upstream.html#L105. I'm wondering what we should do about it. |
I would propose to add a defensive check in the core, it's the least worse solution I can think of. Would it work for you? |
I didn't need it with the 4.0.0 implementation of |
As long as it behaves like the previous implementation, all right for me! |
Ok, I think that we can move forward with that. Thanks for raising. |
If I can add just one more request: can you add the defensive check at the useMediaquery level, so that the migration from withWidth is natural? |
💯 |
If you're using Jest and want to mock it, the following works (at least for my use case): window.matchMedia = jest.fn(() => ({
matches: true,
media: '',
addListener: jest.fn(),
removeListener: jest.fn()
})); I don't know how this changes things internally, but seems fine for a temporary hack to get tests passing... |
Thanks for the super fast fix! |
Since #15678, the
withWidth()
HOC fails on the server-side (in unit tests run with react-testing-library) with the following error:Expected Behavior 🤔
No regression in a bugfix release, unchanged
withWidth()
behavior on the server side since 4.0.0Current Behavior 😯
Because it now uses the
useMediaQuery
hook,withWidth()
fails on the server side.I know I could ask
ssr: false
somehow but I prefer not to deal with that (just likewithWidth
used to work)Steps to Reproduce 🕹
Sorry, I can't provide a link to a CodeSandbox as it only happens in the server side.
Just render a component decorated with withWidth() using react-testing-library to get the error.
Context 🔦
I'm migrating react-admin to material-ui v4 and its hooks.
Your Environment 🌎
The text was updated successfully, but these errors were encountered: