Skip to content
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

React: Fix React 18 react-dom/client dynamic import syntax #17987

Merged
merged 1 commit into from
Apr 18, 2022

Conversation

IanVS
Copy link
Member

@IanVS IanVS commented Apr 17, 2022

Issue: storybookjs/builder-vite#340

What I did

Currently, the dynamic import of react-dom/client does not use the .default, as it should, since dynamic imports work like namespace imports (e.g. import * as dep from 'library'). Perhaps webpack has a compat layer when dealing with commonjs files that is making this work as written, but it's more correct in terms of the es module spec to reference the default property from the module, I believe.

How to test

  • Is this testable with Jest or Chromatic screenshots?
  • Does this need a new example in the kitchen sink apps?
  • Does this need an update to the documentation?

This was passing the tests previously in the vite builder because rollup seems to hoist the default property up to the module, which maybe webpack is doing as well? But, it fails in vite dev. With this change, it passes.

@nx-cloud
Copy link

nx-cloud bot commented Apr 17, 2022

☁️ Nx Cloud Report

CI is running/has finished running commands for commit d19fdec. As they complete they will appear below. Click to see the status, the terminal output, and the build insights.

📂 See all runs for this branch


✅ Successfully ran 1 target

Sent with 💌 from NxCloud.

@shilman
Copy link
Member

shilman commented Apr 17, 2022

@IanVS any idea what's going on with the chromatic snapshot?

@IanVS
Copy link
Member Author

IanVS commented Apr 17, 2022

Hmmm, not sure. The canvas view looks okay, but the snapshot is empty. Maybe the snapshot was taken too quickly before the component rendered in? The fact that it's only one snapshot makes me think it might be a fluke. Do the chromatic snapshots even use react 18?

@IanVS IanVS force-pushed the react-18-import branch from 73c85fd to d19fdec Compare April 18, 2022 01:17
@IanVS
Copy link
Member Author

IanVS commented Apr 18, 2022

@shilman I rebased on next and force-pushed, to run CI again, and the snapshots are all unchanged now. It does indeed seem to have been a fluke.

Copy link
Member

@shilman shilman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for doing that @IanVS 🙏 Merging!

@shilman shilman changed the title Fix React 18 react-dom/client dynamic import syntax React: Fix React 18 react-dom/client dynamic import syntax Apr 18, 2022
@shilman shilman merged commit 396c1a9 into next Apr 18, 2022
@shilman shilman deleted the react-18-import branch April 18, 2022 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants