-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Bump react-shallow-renderer to 16.13.1 #18187
Bump react-shallow-renderer to 16.13.1 #18187
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 2a94183:
|
62d2eb4
to
492020c
Compare
Alternatively, I could introduce a breaking change to Something like // react-shallow-renderer/src/ReactShallowRenderer.js
- export default ReactShallowRenderer;
+ export { ReactShallowRenderer }; // while still keeping the static `createRenderer` property for backwards compat
+ export const createRenderer = function() {
+ return new ReactShallowRenderer();
+ };
// packages/react-test-renderer/npm/shallow.js
- module.exports = require('react-shallow-renderer');
+ module.exports = require('react-shallow-renderer').ReactShallowRenderer;
// packages/react-test-renderer/shallow.js
- export {default} from 'react-shallow-renderer';
+ export {ReactShallowRenderer as default} from 'react-shallow-renderer'; |
Exposing the class was always weird (and probably an accident given createRenderer exists). Unfortunately that's what the docs already show so it's likely people use it widely. |
Yeah I don’t think I should remove the class export. However, given it’s a new package (and it’s unlikely that a lot of people have adopted it already), I’m open to cutting a new major release that uses a named export to export the class. When/if people migrate from @gaearon has suggested via Twitter DM to remove |
One more solution: follow the approach taken in mridgway/hoist-non-react-statics#86 to ensure the CJS version always exports a |
See facebook/react#18187 for context.
See facebook/react#18187 for context.
492020c
to
2a94183
Compare
See facebook/react#18187 for context.
See webpack/webpack#7973
Most recent edit
I've now removed the
module
field fromreact-shallow-renderer
to avoid ESM/CJS interop issues and published v16.13.1 of the package (see related PR enzymejs/react-shallow-renderer#34).Edit
Just came across webpack/webpack#6584 as well
Summary
This change fixes a plausible CJS <-> ESM interop issue in webpack that I mentioned in #18186 (comment) (see webpack/webpack#7973 for details).
I was actually able to reproduce this issue by tweaking
node_modules
(to usereact-shallow-renderer
) and runningyarn test:karma
in Material-UI's repo - https://github.com/mui-org/material-ui/blob/aa0963253bd682d0c08f21114037749e3e9f0817/package.json#L36Although it does pick up the ESM version of
react-shallow-renderer
, Enzyme uses_interopRequireDefault
(https://unpkg.com/browse/enzyme-adapter-react-16@1.15.2/build/ReactSixteenAdapter.js) whenrequire()
-ing it so things don't actually break. But imagine a proper CJS setup (with webpack) where users are doingrequire('react-test-renderer/shallow')
, they could get this.default
key.I'm not so concerned about direct imports of
react-shallow-renderer
(as in, not transitively viareact-test-renderer/shallow
) because it's a new package, so I don't think dropping the ESM build is worth it.Note: this issue doesn't affect Jest (and as a result, CRA).
Test Plan
I modified
react-test-renderer/shallow
like so in Material-UI'snode_modules
:And got the following output: