-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
fix: add tests for React 18, bump peerDeps #22334
Conversation
Thanks for taking the time to open a PR!
|
@@ -155,6 +157,21 @@ export async function makeWebpackConfig ( | |||
], | |||
} | |||
|
|||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a bit of a hack. Since we cannot assume react-dom/client
exists, we import it using a dynamic import: https://github.com/cypress-io/cypress/pull/22334/files#diff-deaf32d610fd1088b9d1a39d5b49198b98fcaba2d2b1b8942df73ed9961551e0R142
import('does-not-exist').then(...).catch(...)
This works fine for "real" ESM, but webpack is not real ESM, but it's own implementation - it does analysis of all modules, including dynamic imports, and will error.
To tell webpack NOT to do this, we can just add it as an external - then webpack will assume it exists at runtime. We can now catch the error!
Unfortunately, this does not seem to work how you'd expect during tests - possibly due to how we use symlinks, or the fact that we ship our module is a kind of weird way (inline inside of node_modules/cypress
.
Storybook solves this differently, using IgnorePlugin
: https://github.com/storybookjs/storybook/pull/17215/files#diff-bc92d51dd98fe78ac7c9251c1b8d10d45bdfc8b872be68c12ace18f783205fd7R16-R18
But I could not get this to work, I am not sure why - possibly due to the weird way we bundle cypress/react
.
In favor of #22437 for now. |
User facing changelog
Add support for React 18 to
npm/react
.Additional details
peerDependencies
to allow installing@cypres/react
withreact@18
react-dom/client
codeSince React projects on <= 17 do not have
react-dom/client
, I did a dynamic import:This is valid in regular ESM, but both webpack and vite are NOT regular ESM... Vite does pre-optimizating, and webpack has it's own
require
function.My solution:
react-dom/client
request if the user is not on react 18react-dom/client
asexternals
for React <= 17 projects. Then we can catch the error, instead of webpack failing to compile due to a missing module.I cannot get the system-tests to work with React 18, but I did build the binary and test it out - seems like it's working as expected.
Many other libs have this problem, eg storybook who solves this with
IngorePlugin
for webpack: https://github.com/storybookjs/storybook/pull/17215/files#diff-bc92d51dd98fe78ac7c9251c1b8d10d45bdfc8b872be68c12ace18f783205fd7R16-R18.Another solution would be remove the react-dom/client dependency, maybe with https://webpack.js.org/plugins/normal-module-replacement-plugin/, but I cannot get this to work, either. I think the problem is that
cypress/react
is NOT a module, but just some inline code we bundle innode_modules/cypress
, but I'm not really sure.Either way, I think we need React 18 support soon, and this seems to be the best solution, other than creating
cypress/react18
, which is not really ideal.Another solution might be having
cypress/react18
in the binary, and dynamically replacingcypress/react
with a webpack or Vite plugin under the hood. cc @JessicaSachs, thoughts?Steps to test
How has the user experience changed?
PR Tasks
cypress-documentation
?type definitions
?