Convert the rest of react-dom and react-test-renderer to Named Exports#18145
Convert the rest of react-dom and react-test-renderer to Named Exports#18145sebmarkbage merged 1 commit intofacebook:masterfrom
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.
Okay this is what confused me. It should say ReactShallowRenderer.
There was a problem hiding this comment.
potato, potato... fixed :)
| return context; | ||
| } | ||
|
|
||
| // This should probably be a default export and a named export. |
There was a problem hiding this comment.
I don't understand what this comment is saying. Which one should it be?
There was a problem hiding this comment.
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.
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.
No, Rollup makes this into module.exports = if you only export a default. (Babel doesn't which is what Jest is struggling with.)
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
|
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