Skip to content

Commit

Permalink
Ensure externalized React entrypoints use vendored React in App Router
Browse files Browse the repository at this point in the history
  • Loading branch information
eps1lon authored and ztanner committed Sep 4, 2024
1 parent e9cbf27 commit eabe1c6
Show file tree
Hide file tree
Showing 33 changed files with 50 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20950,7 +20950,7 @@
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
var Scheduler = require("next/dist/compiled/scheduler-experimental"),
React = require("next/dist/compiled/react-experimental"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom-experimental"),
REACT_LEGACY_ELEMENT_TYPE = Symbol.for("react.element"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"use strict";
var Scheduler = require("next/dist/compiled/scheduler-experimental"),
React = require("next/dist/compiled/react-experimental"),
ReactDOM = require("react-dom");
ReactDOM = require("next/dist/compiled/react-dom-experimental");
function formatProdErrorMessage(code) {
var url = "https://react.dev/errors/" + code;
if (1 < arguments.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21007,7 +21007,7 @@
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
var Scheduler = require("next/dist/compiled/scheduler-experimental"),
React = require("next/dist/compiled/react-experimental"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom-experimental"),
REACT_LEGACY_ELEMENT_TYPE = Symbol.for("react.element"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
var Scheduler = require("next/dist/compiled/scheduler-experimental"),
React = require("next/dist/compiled/react-experimental"),
ReactDOM = require("react-dom");
ReactDOM = require("next/dist/compiled/react-dom-experimental");
function formatProdErrorMessage(code) {
var url = "https://react.dev/errors/" + code;
if (1 < arguments.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7829,7 +7829,7 @@
return result;
}
var React = require("next/dist/compiled/react-experimental"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom-experimental"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
"use strict";
var React = require("next/dist/compiled/react-experimental"),
ReactDOM = require("react-dom");
ReactDOM = require("next/dist/compiled/react-dom-experimental");
function formatProdErrorMessage(code) {
var url = "https://react.dev/errors/" + code;
if (1 < arguments.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7829,7 +7829,7 @@
return result;
}
var React = require("next/dist/compiled/react-experimental"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom-experimental"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
"use strict";
var React = require("next/dist/compiled/react-experimental"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom-experimental"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8185,7 +8185,7 @@
);
}
var React = require("next/dist/compiled/react-experimental"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom-experimental"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
"use strict";
var React = require("next/dist/compiled/react-experimental"),
ReactDOM = require("react-dom");
ReactDOM = require("next/dist/compiled/react-dom-experimental");
function formatProdErrorMessage(code) {
var url = "https://react.dev/errors/" + code;
if (1 < arguments.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

"use strict";
var React = require("next/dist/compiled/react-experimental"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom-experimental"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8208,7 +8208,7 @@
);
}
var React = require("next/dist/compiled/react-experimental"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom-experimental"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
"use strict";
var React = require("next/dist/compiled/react-experimental"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom-experimental"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8098,7 +8098,7 @@
crypto = require("crypto"),
async_hooks = require("async_hooks"),
React = require("next/dist/compiled/react-experimental"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom-experimental"),
stream = require("stream"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var util = require("util"),
crypto = require("crypto"),
async_hooks = require("async_hooks"),
React = require("next/dist/compiled/react-experimental"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom-experimental"),
stream = require("stream"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21234,7 +21234,7 @@
}
var Scheduler = require("next/dist/compiled/scheduler-experimental"),
React = require("next/dist/compiled/react-experimental"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom-experimental"),
REACT_LEGACY_ELEMENT_TYPE = Symbol.for("react.element"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"use strict";
var Scheduler = require("next/dist/compiled/scheduler-experimental"),
React = require("next/dist/compiled/react-experimental"),
ReactDOM = require("react-dom");
ReactDOM = require("next/dist/compiled/react-dom-experimental");
function formatProdErrorMessage(code) {
var url = "https://react.dev/errors/" + code;
if (1 < arguments.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20599,7 +20599,7 @@
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
var Scheduler = require("next/dist/compiled/scheduler"),
React = require("next/dist/compiled/react"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom"),
REACT_LEGACY_ELEMENT_TYPE = Symbol.for("react.element"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"use strict";
var Scheduler = require("next/dist/compiled/scheduler"),
React = require("next/dist/compiled/react"),
ReactDOM = require("react-dom");
ReactDOM = require("next/dist/compiled/react-dom");
function formatProdErrorMessage(code) {
var url = "https://react.dev/errors/" + code;
if (1 < arguments.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20656,7 +20656,7 @@
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
var Scheduler = require("next/dist/compiled/scheduler"),
React = require("next/dist/compiled/react"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom"),
REACT_LEGACY_ELEMENT_TYPE = Symbol.for("react.element"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(Error());
var Scheduler = require("next/dist/compiled/scheduler"),
React = require("next/dist/compiled/react"),
ReactDOM = require("react-dom");
ReactDOM = require("next/dist/compiled/react-dom");
function formatProdErrorMessage(code) {
var url = "https://react.dev/errors/" + code;
if (1 < arguments.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7124,7 +7124,7 @@
return result;
}
var React = require("next/dist/compiled/react"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
"use strict";
var React = require("next/dist/compiled/react"),
ReactDOM = require("react-dom");
ReactDOM = require("next/dist/compiled/react-dom");
function formatProdErrorMessage(code) {
var url = "https://react.dev/errors/" + code;
if (1 < arguments.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7124,7 +7124,7 @@
return result;
}
var React = require("next/dist/compiled/react"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
"use strict";
var React = require("next/dist/compiled/react"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7246,7 +7246,7 @@
}
}
var React = require("next/dist/compiled/react"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
"use strict";
var React = require("next/dist/compiled/react"),
ReactDOM = require("react-dom");
ReactDOM = require("next/dist/compiled/react-dom");
function formatProdErrorMessage(code) {
var url = "https://react.dev/errors/" + code;
if (1 < arguments.length) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

"use strict";
var React = require("next/dist/compiled/react"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7269,7 +7269,7 @@
}
}
var React = require("next/dist/compiled/react"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
*/
"use strict";
var React = require("next/dist/compiled/react"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7135,7 +7135,7 @@
crypto = require("crypto"),
async_hooks = require("async_hooks"),
React = require("next/dist/compiled/react"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var util = require("util"),
crypto = require("crypto"),
async_hooks = require("async_hooks"),
React = require("next/dist/compiled/react"),
ReactDOM = require("react-dom"),
ReactDOM = require("next/dist/compiled/react-dom"),
REACT_ELEMENT_TYPE = Symbol.for("react.transitional.element"),
REACT_PORTAL_TYPE = Symbol.for("react.portal"),
REACT_FRAGMENT_TYPE = Symbol.for("react.fragment"),
Expand Down
31 changes: 18 additions & 13 deletions packages/next/taskfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -1566,6 +1566,22 @@ export async function copy_vendor_react(task_) {
)
}

function aliasVendoredReactPackages(source) {
return source
.replace(
/require\(["']react["']\)/g,
`require("next/dist/compiled/react${packageSuffix}")`
)
.replace(
/require\(["']react-dom["']\)/g,
`require("next/dist/compiled/react-dom${packageSuffix}")`
)
.replace(
/require\(["']scheduler["']\)/g,
`require("next/dist/compiled/scheduler${packageSuffix}")`
)
}

const schedulerDir = dirname(
relative(__dirname, require.resolve(`scheduler-${channel}/package.json`))
)
Expand Down Expand Up @@ -1610,10 +1626,7 @@ export async function copy_vendor_react(task_) {
.run({ every: true }, function* (file) {
const source = file.data.toString()
// We replace the module/chunk loading code with our own implementation in Next.js.
file.data = source.replace(
/require\(["']react["']\)/g,
`require("next/dist/compiled/react${packageSuffix}")`
)
file.data = aliasVendoredReactPackages(source)
})
.target(`src/compiled/react${packageSuffix}/cjs`)

Expand All @@ -1635,15 +1648,7 @@ export async function copy_vendor_react(task_) {
.run({ every: true }, function* (file) {
const source = file.data.toString()
// We replace the module/chunk loading code with our own implementation in Next.js.
let newSource = source
.replace(
/require\(["']scheduler["']\)/g,
`require("next/dist/compiled/scheduler${packageSuffix}")`
)
.replace(
/require\(["']react["']\)/g,
`require("next/dist/compiled/react${packageSuffix}")`
)
let newSource = aliasVendoredReactPackages(source)

const filepath = file.dir + '/' + file.base
if (
Expand Down

0 comments on commit eabe1c6

Please sign in to comment.