-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Convert the rest of react-dom and react-test-renderer to Named Exports #18145
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 5c75e3f:
|
Details of bundled changes.Comparing: 60016c4...5c75e3f react-dom
react-test-renderer
ReactDOM: size: -1.2%, gzip: -1.3% Size changes (experimental) |
Details of bundled changes.Comparing: 60016c4...5c75e3f react-dom
react-test-renderer
ReactDOM: size: -0.1%, gzip: 🔺+0.1% Size changes (stable) |
let ReactDOM; | ||
let ReactDOMServer; | ||
let ReactTestUtils; | ||
import ReactTestRenderer from 'react-test-renderer/shallow'; |
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.
Okay this is what confused me. It should say ReactShallowRenderer
.
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.
potato, potato... fixed :)
@@ -856,4 +856,8 @@ function getMaskedContext(contextTypes, unmaskedContext) { | |||
return context; | |||
} | |||
|
|||
// This should probably be a default export and a named export. |
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.
I don't understand what this comment is saying. Which one should it be?
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.
Both
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.
When we expose a proper ES module we can do:
export default ReactShallowRenderer;
export createRenderer;
It's just that if I do that, then Rollup doesn't do the magic thing to only use module.exports =
// TODO: decide on the top-level export form. | ||
// This is hacky but makes it work with both Rollup and Jest. | ||
module.exports = ReactShallowRenderer.default || ReactShallowRenderer; | ||
export {default} from './src/ReactShallowRenderer'; |
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.
Isn't this gonna break const ShallowRenderer = require('react-test-renderer/shallow')
? Is this not a breaking change?
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.
No, Rollup makes this into module.exports =
if you only export a default. (Babel doesn't which is what Jest is struggling with.)
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.
🤯 I had no idea
Nothing interesting here except that ReactShallowRenderer currently exports a class with a static method instead of an object. I think the public API is probably just meant to be createRenderer but currently the whole class is exposed. So this means that we have to keep it as default export. We could potentially also expose a named export for createRenderer but that's going to cause compatibility issues. So I'm just going to make that export default. Unfortunately Rollup and Babel (which powers Jest) disagree on how to import this. So to make it work I had to move the jest tests to imports. This doesn't work with module resetting. Some tests weren't doing that anyway and the rest is just testing ReactShallowRenderer so meh.
a3d4535
to
5c75e3f
Compare
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.
ok
beautiful |
Nothing interesting here except that ReactShallowRenderer currently exports a class with a static method instead of an object.
I think the public API is probably just meant to be createRenderer but currently the whole class is exposed. So this means that we have to keep it as default export. We could potentially also expose a named export for createRenderer but that's going to cause compatibility issues.
So I'm just going to make that export default.
Unfortunately Rollup and Babel (which powers Jest) disagree on how to import this. So to make it work I had to move the jest tests to imports.
This doesn't work with module resetting. Some tests weren't doing that anyway and the rest is just testing ReactShallowRenderer so meh.
Also see #18144