Skip to content
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

server: bundle vendored react #55362

Merged
merged 59 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
9d114d5
toast
feedthejim Sep 14, 2023
a12c76a
types
feedthejim Sep 14, 2023
906896c
Merge remote-tracking branch 'origin/canary' into feedthejim/bundle-r…
feedthejim Sep 14, 2023
9c45cf0
Revert "types"
feedthejim Sep 14, 2023
1e44d52
fix edge
feedthejim Sep 14, 2023
8193d1b
tree shake typeof window
feedthejim Sep 14, 2023
5c33d38
fix actions
feedthejim Sep 14, 2023
d48d793
update test
feedthejim Sep 14, 2023
eac661a
temporary HMR fix
feedthejim Sep 14, 2023
1425474
Merge remote-tracking branch 'origin/canary' into feedthejim/bundle-r…
feedthejim Sep 14, 2023
3eef508
fix server actions build
feedthejim Sep 14, 2023
886279b
fix bundled react in pages
feedthejim Sep 14, 2023
1eeadc6
tentative require cache fix
feedthejim Sep 14, 2023
8b0c25b
add env var
feedthejim Sep 14, 2023
a3ceceb
fix server config
feedthejim Sep 14, 2023
c5b5e51
fix hmr
feedthejim Sep 14, 2023
f4dd6ee
Revert "tentative require cache fix"
feedthejim Sep 14, 2023
d8b8a96
Merge branch 'canary' into feedthejim/bundle-react
feedthejim Sep 14, 2023
e303a7e
fix use flight response
feedthejim Sep 14, 2023
80e946b
tentatively fix shared-runtimes
feedthejim Sep 14, 2023
1824110
Merge remote-tracking branch 'origin/canary' into feedthejim/bundle-r…
feedthejim Sep 14, 2023
8bc4fcb
update vendored stub
feedthejim Sep 14, 2023
9771525
re-do vendored contexts
feedthejim Sep 14, 2023
f0a4124
simplify require hook
feedthejim Sep 14, 2023
0e0ee06
Merge remote-tracking branch 'origin/canary' into feedthejim/bundle-r…
feedthejim Sep 14, 2023
a4dc693
disable require hook in worker
feedthejim Sep 14, 2023
b92c0e8
add server inserted HTML to pages
feedthejim Sep 14, 2023
a598f5e
fix require hook
feedthejim Sep 14, 2023
bf86e06
add other aliases for react
feedthejim Sep 14, 2023
57bb3bc
fix require hook (again)
feedthejim Sep 14, 2023
25a9a8f
update import map
feedthejim Sep 14, 2023
2f3f315
Merge branch 'canary' into feedthejim/bundle-react
feedthejim Sep 15, 2023
3a13db1
revert scheduler rewrites
feedthejim Sep 15, 2023
57a2cfe
add new resolve plugin
feedthejim Sep 15, 2023
90541a9
undo require changes
feedthejim Sep 15, 2023
1cd252d
fix import mappings
feedthejim Sep 15, 2023
dab2ad1
fix contexts load in turbo
feedthejim Sep 15, 2023
99caa9e
fix edge
feedthejim Sep 15, 2023
615a8d6
fix typo in import map
feedthejim Sep 15, 2023
0673756
move worker env init higher
feedthejim Sep 15, 2023
2237523
fix worker runtime usage
feedthejim Sep 15, 2023
a927bca
try to disable wildcard rule
feedthejim Sep 15, 2023
6b04748
fix hmr
feedthejim Sep 15, 2023
827bb43
clean up
feedthejim Sep 15, 2023
1874883
fix HMR
feedthejim Sep 15, 2023
65d43d6
big cleanup
feedthejim Sep 15, 2023
db67e63
dead code
feedthejim Sep 15, 2023
84825ce
Merge branch 'canary' into feedthejim/bundle-react
kodiakhq[bot] Sep 15, 2023
f9f6945
Merge branch 'canary' into feedthejim/bundle-react
kodiakhq[bot] Sep 15, 2023
485f0ae
manually include vendored contexts files
ijjk Sep 15, 2023
e2db79b
Merge branch 'feedthejim/bundle-react' of github.com:vercel/next.js i…
ijjk Sep 15, 2023
320bc74
Update packages/next-swc/crates/next-core/src/next_shared/resolve.rs
feedthejim Sep 15, 2023
6de51b2
address comments
feedthejim Sep 15, 2023
a2acaed
fix trace path
ijjk Sep 15, 2023
05e7d8b
Merge branch 'feedthejim/bundle-react' of github.com:vercel/next.js i…
ijjk Sep 15, 2023
bf1ad0b
revert vendored react changes
feedthejim Sep 15, 2023
33ec18b
remove typeof window define
feedthejim Sep 15, 2023
dcef2aa
Merge branch 'canary' into feedthejim/bundle-react
kodiakhq[bot] Sep 15, 2023
4a967fa
bump
ijjk Sep 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions packages/next/src/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ import { generateInterceptionRoutesRewrites } from '../lib/generate-interception

import { buildDataRoute } from '../server/lib/router-utils/build-data-route'
import {
baseOverrides,
// baseOverrides,
defaultOverrides,
experimentalOverrides,
// experimentalOverrides,
} from '../server/import-overrides'
import { initialize as initializeIncrementalCache } from '../server/lib/incremental-cache-server'
import { nodeFs } from '../server/lib/node-fs-methods'
Expand Down Expand Up @@ -2112,12 +2112,12 @@ export default async function build(
)

const sharedEntriesSet = [
...Object.values(baseOverrides).map((override) =>
require.resolve(override)
),
...Object.values(experimentalOverrides).map((override) =>
require.resolve(override)
),
// ...Object.values(baseOverrides).map((override) =>
// require.resolve(override)
// ),
// ...Object.values(experimentalOverrides).map((override) =>
// require.resolve(override)
// ),
...(config.experimental.turbotrace
? []
: Object.keys(defaultOverrides).map((value) =>
Expand Down
251 changes: 159 additions & 92 deletions packages/next/src/build/webpack-config.ts

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,30 @@ const originModules = [
require.resolve('../../../server/require'),
require.resolve('../../../server/load-components'),
require.resolve('../../../server/next-server'),
require.resolve('../../../compiled/react-server-dom-webpack/client.edge'),
require.resolve(
'../../../compiled/react-server-dom-webpack-experimental/client.edge'
),
// require.resolve('../../../compiled/react-server-dom-webpack/client.edge'),
// require.resolve(
// '../../../compiled/react-server-dom-webpack-experimental/client.edge'
// ),
]

const RUNTIME_NAMES = ['webpack-runtime', 'webpack-api-runtime']

export function deleteAppClientCache() {
// ensure we reset the cache for rsc components
// loaded via react-server-dom-webpack
const reactServerDomModId = require.resolve(
'react-server-dom-webpack/client.edge'
)
const reactServerDomMod = require.cache[reactServerDomModId]
return
// // ensure we reset the cache for rsc components
// // loaded via react-server-dom-webpack
// const reactServerDomModId = require.resolve(
// 'react-server-dom-webpack/client.edge'
// )
// const reactServerDomMod = require.cache[reactServerDomModId]

if (reactServerDomMod) {
for (const child of reactServerDomMod.children) {
child.parent = null
delete require.cache[child.id]
}
}
delete require.cache[reactServerDomModId]
// if (reactServerDomMod) {
// for (const child of reactServerDomMod.children) {
// child.parent = null
// delete require.cache[child.id]
// }
// }
// delete require.cache[reactServerDomModId]
}

export function deleteCache(filePath: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

// @ts-ignore
// eslint-disable-next-line import/no-extraneous-dependencies
import { createFromFetch } from 'react-server-dom-webpack/client'
// import { createFromFetch } from 'react-server-dom-webpack/client'
const { createFromFetch } = (
typeof window === 'undefined'
feedthejim marked this conversation as resolved.
Show resolved Hide resolved
? // eslint-disable-next-line import/no-extraneous-dependencies
require('react-server-dom-webpack/client.edge')
: // eslint-disable-next-line import/no-extraneous-dependencies
require('react-server-dom-webpack/client')
) as typeof import('react-server-dom-webpack/client')

import type {
FlightRouterState,
FlightData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,17 @@ import {
} from '../../app-router-headers'
import { createRecordFromThenable } from '../create-record-from-thenable'
import { readRecordValue } from '../read-record-value'
// eslint-disable-next-line import/no-extraneous-dependencies
import { createFromFetch } from 'react-server-dom-webpack/client'
// eslint-disable-next-line import/no-extraneous-dependencies
import { encodeReply } from 'react-server-dom-webpack/client'
// // eslint-disable-next-line import/no-extraneous-dependencies
// import { createFromFetch } from 'react-server-dom-webpack/client'
// // eslint-disable-next-line import/no-extraneous-dependencies
// import { encodeReply } from 'react-server-dom-webpack/client'
const { createFromFetch, encodeReply } = (
typeof window === 'undefined'
? // eslint-disable-next-line import/no-extraneous-dependencies
require('react-server-dom-webpack/client.edge')
: // eslint-disable-next-line import/no-extraneous-dependencies
require('react-server-dom-webpack/client')
) as typeof import('react-server-dom-webpack/client')

import {
ReadonlyReducerState,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (process.env.NODE_ENV !== "production") {
(function() {
'use strict';

var React = require("next/dist/compiled/react-experimental");
var React = require('react');
var ReactDOM = require('react-dom');

var ReactVersion = '18.3.0-experimental-dd480ef92-20230822';
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (process.env.NODE_ENV !== "production") {
(function() {
'use strict';

var React = require("next/dist/compiled/react-experimental");
var React = require('react');
var ReactDOM = require('react-dom');
var stream = require('stream');

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (process.env.NODE_ENV !== "production") {
(function() {
'use strict';

var React = require("next/dist/compiled/react-experimental");
var React = require('react');

var ReactVersion = '18.3.0-experimental-dd480ef92-20230822';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
'use strict';var d=require("next/dist/compiled/react-experimental"),e={usingClientEntryPoint:!1,Events:null,Dispatcher:{current:null}};function f(b){for(var a="https://reactjs.org/docs/error-decoder.html?invariant="+b,c=1;c<arguments.length;c++)a+="&args[]="+encodeURIComponent(arguments[c]);return"Minified React error #"+b+"; visit "+a+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var g=e.Dispatcher,h=d.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher;
'use strict';var d=require("react"),e={usingClientEntryPoint:!1,Events:null,Dispatcher:{current:null}};function f(b){for(var a="https://reactjs.org/docs/error-decoder.html?invariant="+b,c=1;c<arguments.length;c++)a+="&args[]="+encodeURIComponent(arguments[c]);return"Minified React error #"+b+"; visit "+a+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var g=e.Dispatcher,h=d.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentDispatcher;
exports.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=e;exports.createPortal=function(){throw Error(f(448));};exports.experimental_useFormStatus=function(){return h.current.useHostTransitionStatus()};exports.flushSync=function(){throw Error(f(449));};exports.preconnect=function(b,a){var c=g.current;c&&c.preconnect(b,a)};exports.prefetchDNS=function(b){var a=g.current;a&&a.prefetchDNS(b)};exports.preinit=function(b,a){var c=g.current;c&&c.preinit(b,a)};
exports.preload=function(b,a){var c=g.current;c&&c.preload(b,a)};exports.unstable_batchedUpdates=function(b,a){return b(a)};exports.version="18.3.0-experimental-dd480ef92-20230822";
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (process.env.NODE_ENV !== "production") {
(function() {
'use strict';

var React = require("next/dist/compiled/react-experimental");
var React = require('react');
var ReactDOM = require('react-dom');

var ReactVersion = '18.3.0-experimental-dd480ef92-20230822';
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (process.env.NODE_ENV !== "production") {
(function() {
'use strict';

var React = require("next/dist/compiled/react-experimental");
var React = require('react');
var ReactDOM = require('react-dom');

var ReactVersion = '18.3.0-experimental-dd480ef92-20230822';
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (process.env.NODE_ENV !== "production") {
(function() {
'use strict';

var React = require("next/dist/compiled/react-experimental");
var React = require('react');
var util = require('util');
var async_hooks = require('async_hooks');
var ReactDOM = require('react-dom');
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if (process.env.NODE_ENV !== "production") {
(function() {
'use strict';

var React = require("next/dist/compiled/react-experimental");
var React = require('react');
var ReactDOM = require('react-dom');

var ReactVersion = '18.3.0-experimental-dd480ef92-20230822';
Expand Down
Loading