React version: N/A (Build tooling issue on main as of commit 0131d0c )
Steps To Reproduce
- Clone, install, and run
yarn build
- Inspect
build/oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.js
- Scroll to line 300, around
var reservedProps =. Compare with react-dom-bindings/src/shared/DOMProperty.js. Note that:
- There is no
properties object in the build output
- The lines that should say
properties[name] = new PropertyInfoRecord(....) are missing the assignment, and only say new PropertyInfoRecord()
- A couple of the associated constants like
const RESERVED = 0 are also missing
This appears to be a bug in Rollup's tree-shaking behavior. If the Rollup config in build.js is modified to say moduleSideEffects: 'safest', the missing content appears in these bundles.
Per experimentation, this can be addressed by adding a custom Rollup plugin that specifically tells Rollup "this code has side effects, don't tree-shake it" (based on rollup/rollup#4090 (comment) ):
module.exports = function disableTreeshake() {
return {
name: 'scripts/rollup/plugins/disable-treeshake',
transform(code, id) {
// Fix issue with `react-dom-webpack-server` bundles accidentally
// stripping out the `properties` object and not filling it out
if (id.endsWith('DOMProperty.js')) {
return {
code,
map: null,
moduleSideEffects: 'no-treeshake',
};
}
return null;
},
};
};
Link to code example:
The current behavior
The full code from DOMProperty.js does not show up in those react-dom-webpack-server bundles
The expected behavior
The DOMProperty output should show up.
React version: N/A (Build tooling issue on
mainas of commit0131d0c)Steps To Reproduce
yarn buildbuild/oss-stable/react-server-dom-webpack/cjs/react-server-dom-webpack-server.browser.development.jsvar reservedProps =. Compare withreact-dom-bindings/src/shared/DOMProperty.js. Note that:propertiesobject in the build outputproperties[name] = new PropertyInfoRecord(....)are missing the assignment, and only saynew PropertyInfoRecord()const RESERVED = 0are also missingThis appears to be a bug in Rollup's tree-shaking behavior. If the Rollup config in
build.jsis modified to saymoduleSideEffects: 'safest', the missing content appears in these bundles.Per experimentation, this can be addressed by adding a custom Rollup plugin that specifically tells Rollup "this code has side effects, don't tree-shake it" (based on rollup/rollup#4090 (comment) ):
Link to code example:
The current behavior
The full code from
DOMProperty.jsdoes not show up in thosereact-dom-webpack-serverbundlesThe expected behavior
The
DOMPropertyoutput should show up.