Skip to content

Commit

Permalink
Update Rollup to 3.x (#26442)
Browse files Browse the repository at this point in the history
<!--
  Thanks for submitting a pull request!
We appreciate you spending the time to work on these changes. Please
provide enough information so that others can review your pull request.
The three fields below are mandatory.

Before submitting a pull request, please make sure the following is
done:

1. Fork [the repository](https://github.com/facebook/react) and create
your branch from `main`.
  2. Run `yarn` in the repository root.
3. If you've fixed a bug or added code that should be tested, add tests!
4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch
TestName` is helpful in development.
5. Run `yarn test --prod` to test in the production environment. It
supports the same options as `yarn test`.
6. If you need a debugger, run `yarn test --debug --watch TestName`,
open `chrome://inspect`, and press "Inspect".
7. Format your code with
[prettier](https://github.com/prettier/prettier) (`yarn prettier`).
8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only
check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

Learn more about contributing:
https://reactjs.org/docs/how-to-contribute.html
-->

## Summary

This PR:

- Updates Rollup from 2.x to latest 3.x, and updates associated plugins
- Updates deprecated / altered config settings in the Rollup plugin
pipeline
- Fixes some file extension and import issues related to use of ESM in
`react-dom-webpack-server`
- Removes a now-obsolete `strip-unused-imports` Rollup plugin
- <s>Fixes an _existing_ bug with the Rollup 2.x plugin pipeline on
`main` that was causing parts of `DOMProperty.js` to get left out of the
`react-dom-webpack-server` JS bundles, by adding a new plugin to tell
Rollup to treat that file as if it as side effects</s>

This PR should be functionally identical to the other existing "Rollup 3
upgrade" PR at #26078 . I'm filing this as a near-duplicate because I'm
ready to push this change through ASAP so that I can follow it up with a
PR that adds sourcemap support, that PR's artifact diffing seems like
it's possibly stuck and I want to compare the build results, and I've
got this set up against latest `main`.

<!--
Explain the **motivation** for making this change. What existing problem
does the pull request solve?
-->

This gets React's build setup updated to the latest Rollup version,
which is generally a good practice, but also ensures that any further
Rollup config tweaks can be done using the current Rollup docs as a
reference.

## How did you test this change?

<!--
Demonstrate the code is solid. Example: The exact commands you ran and
their output, screenshots / videos if the pull request changes the user
interface.
How exactly did you verify that your PR solves the issue you wanted to
solve?
  If you leave this empty, your PR will very likely be closed.
-->

- Made builds from the latest `main`
- Updated Rollup package versions and cross-compared the changes I
needed to make locally to get successful builds vs #26078
- Diffed the output folders between `main` and this PR, and confirmed
that the bundle contents are identical (with the exception of version
strings and the `react-dom-webpack-server` bundle fix re-adding missing
`DOMProperty.js` content)

DiffTrain build for [909c6da](909c6da)
  • Loading branch information
gaearon committed Mar 24, 2023
1 parent c6d6bdf commit 1c9327e
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 450 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9c54b29b44d24f8f8090da9c7ebf569747a444df
909c6dacfde06b87fa22f2e8506c47124cf982b5
4 changes: 2 additions & 2 deletions compiled/facebook-www/ReactART-prod.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -9635,7 +9635,7 @@ var slice = Array.prototype.slice,
return null;
},
bundleType: 0,
version: "18.3.0-www-modern-1925ba21",
version: "18.3.0-www-modern-b7692384",
rendererPackageName: "react-art"
};
var internals$jscomp$inline_1323 = {
Expand Down Expand Up @@ -9666,7 +9666,7 @@ var internals$jscomp$inline_1323 = {
scheduleRoot: null,
setRefreshHandler: null,
getCurrentFiber: null,
reconcilerVersion: "18.3.0-www-modern-1925ba21"
reconcilerVersion: "18.3.0-www-modern-b7692384"
};
if ("undefined" !== typeof __REACT_DEVTOOLS_GLOBAL_HOOK__) {
var hook$jscomp$inline_1324 = __REACT_DEVTOOLS_GLOBAL_HOOK__;
Expand Down
7 changes: 2 additions & 5 deletions compiled/facebook-www/ReactDOM-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -21994,9 +21994,7 @@ function readContextDuringReconcilation(consumer, context, renderLanes) {
}

function readContextForConsumer(consumer, context) {
var value = isPrimaryRenderer
? context._currentValue
: context._currentValue2;
var value = context._currentValue;

if (lastFullyObservedContext === context);
else {
Expand Down Expand Up @@ -33524,7 +33522,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-www-modern-1925ba21";
var ReactVersion = "18.3.0-www-modern-b7692384";

function createPortal$1(
children,
Expand Down Expand Up @@ -42373,7 +42371,6 @@ function getCurrentEventPriority() {

return getEventPriority(currentEvent.type);
}
var isPrimaryRenderer = true;
// if a component just imports ReactDOM (e.g. for findDOMNode).
// Some environments might not have setTimeout or clearTimeout.

Expand Down
7 changes: 2 additions & 5 deletions compiled/facebook-www/ReactDOMTesting-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -24823,9 +24823,7 @@ function readContextDuringReconcilation(consumer, context, renderLanes) {
}

function readContextForConsumer(consumer, context) {
var value = isPrimaryRenderer
? context._currentValue
: context._currentValue2;
var value = context._currentValue;

if (lastFullyObservedContext === context);
else {
Expand Down Expand Up @@ -36865,7 +36863,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-www-classic-ac60b8a6";
var ReactVersion = "18.3.0-www-classic-08ca8562";

function createPortal$1(
children,
Expand Down Expand Up @@ -40017,7 +40015,6 @@ function getCurrentEventPriority() {

return getEventPriority(currentEvent.type);
}
var isPrimaryRenderer = true;
// if a component just imports ReactDOM (e.g. for findDOMNode).
// Some environments might not have setTimeout or clearTimeout.

Expand Down
7 changes: 2 additions & 5 deletions compiled/facebook-www/ReactDOMTesting-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -22128,9 +22128,7 @@ function readContextDuringReconcilation(consumer, context, renderLanes) {
}

function readContextForConsumer(consumer, context) {
var value = isPrimaryRenderer
? context._currentValue
: context._currentValue2;
var value = context._currentValue;

if (lastFullyObservedContext === context);
else {
Expand Down Expand Up @@ -34141,7 +34139,7 @@ function createFiberRoot(
return root;
}

var ReactVersion = "18.3.0-www-modern-c338eadf";
var ReactVersion = "18.3.0-www-modern-ea61562f";

function createPortal$1(
children,
Expand Down Expand Up @@ -42992,7 +42990,6 @@ function getCurrentEventPriority() {

return getEventPriority(currentEvent.type);
}
var isPrimaryRenderer = true;
// if a component just imports ReactDOM (e.g. for findDOMNode).
// Some environments might not have setTimeout or clearTimeout.

Expand Down
162 changes: 3 additions & 159 deletions compiled/facebook-www/ReactFlightDOMRelayServer-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,6 @@ var OVERLOADED_BOOLEAN = 4; // An attribute that must be numeric or parse as a n
// When falsy, it should be removed.

var NUMERIC = 5; // An attribute that must be positive numeric or parse as a positive numeric.
// When falsy, it should be removed.

var POSITIVE_NUMERIC = 6;

function PropertyInfoRecord(
name,
Expand All @@ -240,27 +237,6 @@ function PropertyInfoRecord(
this.sanitizeURL = sanitizeURL;
this.removeEmptyString = removeEmptyString;
} // When adding attributes to this list, be sure to also add them to
// This is a mapping from React prop names to the attribute names.

[
["acceptCharset", "accept-charset"],
["className", "class"],
["htmlFor", "for"],
["httpEquiv", "http-equiv"]
].forEach(function (_ref) {
var name = _ref[0],
attributeName = _ref[1];
// $FlowFixMe[invalid-constructor] Flow no longer supports calling new on functions
new PropertyInfoRecord(
name,
STRING,
false, // mustUseProperty
attributeName, // attributeName
null, // attributeNamespace
false, // sanitizeURL
false
);
}); // These are "enumerated" HTML attributes that accept "true" and "false".
// In React, we let users pass `true` and `false` even though technically
// these aren't boolean attributes (they are coerced to strings).

Expand All @@ -278,27 +254,6 @@ function PropertyInfoRecord(
false
);
}); // These are "enumerated" SVG attributes that accept "true" and "false".
// In React, we let users pass `true` and `false` even though technically
// these aren't boolean attributes (they are coerced to strings).
// Since these are SVG attributes, their attribute names are case-sensitive.

[
"autoReverse",
"externalResourcesRequired",
"focusable",
"preserveAlpha"
].forEach(function (name) {
// $FlowFixMe[invalid-constructor] Flow no longer supports calling new on functions
new PropertyInfoRecord(
name,
BOOLEANISH_STRING,
false, // mustUseProperty
name, // attributeName
null, // attributeNamespace
false, // sanitizeURL
false
);
}); // These are HTML boolean attributes.

[
"allowFullScreen",
Expand Down Expand Up @@ -337,67 +292,6 @@ function PropertyInfoRecord(
false
);
}); // These are the few React props that we set as DOM properties
// rather than attributes. These are all booleans.

[
"checked", // Note: `option.selected` is not updated if `select.multiple` is
// disabled with `removeAttribute`. We have special logic for handling this.
"multiple",
"muted",
"selected" // NOTE: if you add a camelCased prop to this list,
// you'll need to set attributeName to name.toLowerCase()
// instead in the assignment below.
].forEach(function (name) {
// $FlowFixMe[invalid-constructor] Flow no longer supports calling new on functions
new PropertyInfoRecord(
name,
BOOLEAN,
true, // mustUseProperty
name, // attributeName
null, // attributeNamespace
false, // sanitizeURL
false
);
}); // These are HTML attributes that are "overloaded booleans": they behave like
// booleans, but can also accept a string value.

[
"capture",
"download" // NOTE: if you add a camelCased prop to this list,
// you'll need to set attributeName to name.toLowerCase()
// instead in the assignment below.
].forEach(function (name) {
// $FlowFixMe[invalid-constructor] Flow no longer supports calling new on functions
new PropertyInfoRecord(
name,
OVERLOADED_BOOLEAN,
false, // mustUseProperty
name, // attributeName
null, // attributeNamespace
false, // sanitizeURL
false
);
}); // These are HTML attributes that must be positive numbers.

[
"cols",
"rows",
"size",
"span" // NOTE: if you add a camelCased prop to this list,
// you'll need to set attributeName to name.toLowerCase()
// instead in the assignment below.
].forEach(function (name) {
// $FlowFixMe[invalid-constructor] Flow no longer supports calling new on functions
new PropertyInfoRecord(
name,
POSITIVE_NUMERIC,
false, // mustUseProperty
name, // attributeName
null, // attributeNamespace
false, // sanitizeURL
false
);
}); // These are HTML attributes that must be numbers.

["rowSpan", "start"].forEach(function (name) {
// $FlowFixMe[invalid-constructor] Flow no longer supports calling new on functions
Expand Down Expand Up @@ -499,17 +393,7 @@ var capitalize = function (token) {
// you'll need to set attributeName to name.toLowerCase()
// instead in the assignment below.
].forEach(function (attributeName) {
var name = attributeName.replace(CAMELIZE, capitalize); // $FlowFixMe[invalid-constructor] Flow no longer supports calling new on functions

new PropertyInfoRecord(
name,
STRING,
false, // mustUseProperty
attributeName,
null, // attributeNamespace
false, // sanitizeURL
false
);
attributeName.replace(CAMELIZE, capitalize); // $FlowFixMe[invalid-constructor] Flow no longer supports calling new on functions
}); // String SVG attributes with the xlink namespace.

[
Expand All @@ -522,17 +406,7 @@ var capitalize = function (token) {
// you'll need to set attributeName to name.toLowerCase()
// instead in the assignment below.
].forEach(function (attributeName) {
var name = attributeName.replace(CAMELIZE, capitalize); // $FlowFixMe[invalid-constructor] Flow no longer supports calling new on functions

new PropertyInfoRecord(
name,
STRING,
false, // mustUseProperty
attributeName,
"http://www.w3.org/1999/xlink",
false, // sanitizeURL
false
);
attributeName.replace(CAMELIZE, capitalize); // $FlowFixMe[invalid-constructor] Flow no longer supports calling new on functions
}); // String SVG attributes with the xml namespace.

[
Expand All @@ -542,17 +416,7 @@ var capitalize = function (token) {
// you'll need to set attributeName to name.toLowerCase()
// instead in the assignment below.
].forEach(function (attributeName) {
var name = attributeName.replace(CAMELIZE, capitalize); // $FlowFixMe[invalid-constructor] Flow no longer supports calling new on functions

new PropertyInfoRecord(
name,
STRING,
false, // mustUseProperty
attributeName,
"http://www.w3.org/XML/1998/namespace",
false, // sanitizeURL
false
);
attributeName.replace(CAMELIZE, capitalize); // $FlowFixMe[invalid-constructor] Flow no longer supports calling new on functions
}); // These attribute exists both in HTML and SVG.
// The attribute name is case-sensitive in SVG so we can't just use
// the React name like we do for attributes that exist only in HTML.
Expand All @@ -569,26 +433,6 @@ var capitalize = function (token) {
false
);
}); // These attributes accept URLs. These must not allow javascript: URLS.

new PropertyInfoRecord(
"xlinkHref",
STRING,
false, // mustUseProperty
"xlink:href",
"http://www.w3.org/1999/xlink",
true, // sanitizeURL
false
);

new PropertyInfoRecord(
"formAction",
STRING,
false, // mustUseProperty
"formaction", // attributeName
null, // attributeNamespace
true, // sanitizeURL
false
);
["src", "href", "action"].forEach(function (attributeName) {
// $FlowFixMe[invalid-constructor] Flow no longer supports calling new on functions
new PropertyInfoRecord(
Expand Down
Loading

0 comments on commit 1c9327e

Please sign in to comment.