Skip to content

Commit

Permalink
fix bundling and aliasing
Browse files Browse the repository at this point in the history
  • Loading branch information
shuding committed Oct 11, 2022
1 parent 99eea31 commit a50d7f8
Show file tree
Hide file tree
Showing 20 changed files with 126 additions and 122 deletions.
5 changes: 4 additions & 1 deletion packages/next/build/entries.ts
Expand Up @@ -209,7 +209,10 @@ export function getEdgeServerEntry(opts: {

return {
import: `next-edge-ssr-loader?${stringify(loaderParams)}!`,
layer: opts.isServerComponent ? WEBPACK_LAYERS.server : undefined,
// The Edge bundle includes the server in its entrypoint, so it has to
// be in the SSR layer — we later convert the page request to the RSC layer
// via a webpack rule.
layer: undefined,
}
}

Expand Down
85 changes: 43 additions & 42 deletions packages/next/build/webpack-config.ts
Expand Up @@ -874,7 +874,9 @@ export default async function getBaseWebpackConfig(
'react-dom/server$': 'next/dist/compiled/react-dom/server',
'react-dom/server.browser$':
'next/dist/compiled/react-dom/server.browser',
react$: 'next/dist/compiled/react',
// react$: 'next/dist/compiled/react',
'react/jsx-dev-runtime$':
'next/dist/compiled/react/jsx-dev-runtime',
}
: undefined),

Expand Down Expand Up @@ -1539,6 +1541,17 @@ export default async function getBaseWebpackConfig(
},
module: {
rules: [
...(hasAppDir && isEdgeServer
? [
// The Edge bundle includes the server in its entrypoint, so it has to
// be in the SSR layer — here we convert the actual page request to
// the RSC layer via a webpack rule.
{
resourceQuery: /__edge_ssr_entry__/,
layer: WEBPACK_LAYERS.server,
},
]
: []),
...(hasAppDir && !isClient && !isEdgeServer
? [
{
Expand All @@ -1558,31 +1571,16 @@ export default async function getBaseWebpackConfig(

return true
},
resolve:
// process.env.__NEXT_REACT_CHANNEL
// ? {
// conditionNames: ['react-server', 'node', 'require'],
// // alias: {
// // react: `react-${process.env.__NEXT_REACT_CHANNEL}`,
// // 'react-dom': `react-dom-${process.env.__NEXT_REACT_CHANNEL}`,
// // },
// }
// :
{
conditionNames: ['react-server', 'node', 'require'],
alias: {
react: require.resolve(
'next/dist/compiled/react/react.shared-subset'
),
// 'react-dom': 'next/dist/compiled/react-dom',
},
// // If missing the alias override here, the default alias will be used which aliases
// // react to the direct file path, not the package name. In that case the condition
// // will be ignored completely.
// react: 'react',
// 'react-dom': 'react-dom',
// },
resolve: {
conditionNames: ['react-server', 'node', 'require'],
alias: {
// If missing the alias override here, the default alias will be used which aliases
// react to the direct file path, not the package name. In that case the condition
// will be ignored completely.
react: 'react',
'react-dom': 'react-dom',
},
},
},
]
: []),
Expand All @@ -1602,27 +1600,30 @@ export default async function getBaseWebpackConfig(

...(hasServerComponents
? [
// Alias `next/dynamic` to React.lazy implementation for RSC
{
test: codeCondition.test,
include: [appDir],
resolve: {
alias: {
[require.resolve('next/dynamic')]: require.resolve(
'next/dist/client/components/dynamic'
),
oneOf: [
{
issuerLayer: WEBPACK_LAYERS.server,
resolve: {
alias: {
// Alias `next/dynamic` to React.lazy implementation for RSC
[require.resolve('next/dynamic')]: require.resolve(
'next/dist/client/components/dynamic'
),
react: 'next/dist/compiled/react/react.shared-subset',
},
},
},
},
},
{
test: codeCondition.test,
// include: [appDir, dir, NEXT_PROJECT_ROOT_DIST, /node_modules/],
resolve: {
alias: {
'react-dom': 'next/dist/compiled/react-dom',
react: 'next/dist/compiled/react',
{
resolve: {
alias: {
'react-dom': 'next/dist/compiled/react-dom',
react: 'next/dist/compiled/react',
},
},
},
},
],
},
]
: []),
Expand Down
Expand Up @@ -85,7 +85,7 @@ export default async function edgeSSRLoader(this: any) {
const pageModPath = `${appDirLoader}${stringifiedPagePath.substring(
1,
stringifiedPagePath.length - 1
)}`
)}?__edge_ssr_entry__`

const transformed = `
import { adapter, enhanceGlobals } from 'next/dist/esm/server/web/adapter'
Expand Down
14 changes: 7 additions & 7 deletions packages/next/compiled/babel/bundle.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions packages/next/compiled/react-dom/client.js
Expand Up @@ -30,7 +30,7 @@ if (
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var React = __nccwpck_require__(533);
var React = __nccwpck_require__(522);
var Scheduler = __nccwpck_require__(41);

var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
Expand Down Expand Up @@ -32058,7 +32058,7 @@ if (
/*
Modernizr 3.0.0pre (Custom Build) | MIT
*/
var aa=__nccwpck_require__(533),ba=__nccwpck_require__(41),p=Object.assign;function y(a){for(var b="https://reactjs.org/docs/error-decoder.html?invariant="+a,c=1;c<arguments.length;c++)b+="&args[]="+encodeURIComponent(arguments[c]);return"Minified React error #"+a+"; visit "+b+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}
var aa=__nccwpck_require__(522),ba=__nccwpck_require__(41),p=Object.assign;function y(a){for(var b="https://reactjs.org/docs/error-decoder.html?invariant="+a,c=1;c<arguments.length;c++)b+="&args[]="+encodeURIComponent(arguments[c]);return"Minified React error #"+a+"; visit "+b+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}
var ca=aa.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,ea=Symbol.for("react.element"),fa=Symbol.for("react.portal"),ha=Symbol.for("react.fragment"),ia=Symbol.for("react.strict_mode"),ja=Symbol.for("react.profiler"),ka=Symbol.for("react.provider"),la=Symbol.for("react.context"),ma=Symbol.for("react.server_context"),na=Symbol.for("react.forward_ref"),oa=Symbol.for("react.suspense"),pa=Symbol.for("react.suspense_list"),qa=Symbol.for("react.memo"),ra=Symbol.for("react.lazy"),sa=Symbol.for("react.scope");
Symbol.for("react.debug_trace_mode");var ta=Symbol.for("react.offscreen"),ua=Symbol.for("react.legacy_hidden"),va=Symbol.for("react.cache");Symbol.for("react.tracing_marker");var wa=Symbol.for("react.default_value"),xa=Symbol.iterator;function ya(a){if(null===a||"object"!==typeof a)return null;a=xa&&a[xa]||a["@@iterator"];return"function"===typeof a?a:null}
function Ba(a){if(null==a)return null;if("function"===typeof a)return a.displayName||a.name||null;if("string"===typeof a)return a;switch(a){case ha:return"Fragment";case fa:return"Portal";case ja:return"Profiler";case ia:return"StrictMode";case oa:return"Suspense";case pa:return"SuspenseList";case va:return"Cache"}if("object"===typeof a)switch(a.$$typeof){case la:return(a.displayName||"Context")+".Consumer";case ka:return(a._context.displayName||"Context")+".Provider";case na:var b=a.render;a=a.displayName;
Expand Down Expand Up @@ -33136,10 +33136,10 @@ if (process.env.NODE_ENV === 'production') {

/***/ }),

/***/ 533:
/***/ 522:
/***/ ((module) => {

module.exports = require("next/dist/compiled/react");
module.exports = require("react");

/***/ })

Expand Down
8 changes: 4 additions & 4 deletions packages/next/compiled/react-dom/index.js
Expand Up @@ -30,7 +30,7 @@ if (
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var React = __nccwpck_require__(533);
var React = __nccwpck_require__(522);
var Scheduler = __nccwpck_require__(41);

var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
Expand Down Expand Up @@ -32058,7 +32058,7 @@ if (
/*
Modernizr 3.0.0pre (Custom Build) | MIT
*/
var aa=__nccwpck_require__(533),ba=__nccwpck_require__(41),p=Object.assign;function y(a){for(var b="https://reactjs.org/docs/error-decoder.html?invariant="+a,c=1;c<arguments.length;c++)b+="&args[]="+encodeURIComponent(arguments[c]);return"Minified React error #"+a+"; visit "+b+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}
var aa=__nccwpck_require__(522),ba=__nccwpck_require__(41),p=Object.assign;function y(a){for(var b="https://reactjs.org/docs/error-decoder.html?invariant="+a,c=1;c<arguments.length;c++)b+="&args[]="+encodeURIComponent(arguments[c]);return"Minified React error #"+a+"; visit "+b+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}
var ca=aa.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,ea=Symbol.for("react.element"),fa=Symbol.for("react.portal"),ha=Symbol.for("react.fragment"),ia=Symbol.for("react.strict_mode"),ja=Symbol.for("react.profiler"),ka=Symbol.for("react.provider"),la=Symbol.for("react.context"),ma=Symbol.for("react.server_context"),na=Symbol.for("react.forward_ref"),oa=Symbol.for("react.suspense"),pa=Symbol.for("react.suspense_list"),qa=Symbol.for("react.memo"),ra=Symbol.for("react.lazy"),sa=Symbol.for("react.scope");
Symbol.for("react.debug_trace_mode");var ta=Symbol.for("react.offscreen"),ua=Symbol.for("react.legacy_hidden"),va=Symbol.for("react.cache");Symbol.for("react.tracing_marker");var wa=Symbol.for("react.default_value"),xa=Symbol.iterator;function ya(a){if(null===a||"object"!==typeof a)return null;a=xa&&a[xa]||a["@@iterator"];return"function"===typeof a?a:null}
function Ba(a){if(null==a)return null;if("function"===typeof a)return a.displayName||a.name||null;if("string"===typeof a)return a;switch(a){case ha:return"Fragment";case fa:return"Portal";case ja:return"Profiler";case ia:return"StrictMode";case oa:return"Suspense";case pa:return"SuspenseList";case va:return"Cache"}if("object"===typeof a)switch(a.$$typeof){case la:return(a.displayName||"Context")+".Consumer";case ka:return(a._context.displayName||"Context")+".Provider";case na:var b=a.render;a=a.displayName;
Expand Down Expand Up @@ -33136,10 +33136,10 @@ if (process.env.NODE_ENV === 'production') {

/***/ }),

/***/ 533:
/***/ 522:
/***/ ((module) => {

module.exports = require("next/dist/compiled/react");
module.exports = require("react");

/***/ })

Expand Down
8 changes: 4 additions & 4 deletions packages/next/compiled/react-dom/profiling.js
Expand Up @@ -30,7 +30,7 @@ if (
) {
__REACT_DEVTOOLS_GLOBAL_HOOK__.registerInternalModuleStart(new Error());
}
var React = __nccwpck_require__(533);
var React = __nccwpck_require__(522);
var Scheduler = __nccwpck_require__(41);

var ReactSharedInternals = React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
Expand Down Expand Up @@ -32069,7 +32069,7 @@ if (
/*
Modernizr 3.0.0pre (Custom Build) | MIT
*/
'use strict';var aa=__nccwpck_require__(533),p=__nccwpck_require__(41),q=Object.assign;function z(a){for(var b="https://reactjs.org/docs/error-decoder.html?invariant="+a,c=1;c<arguments.length;c++)b+="&args[]="+encodeURIComponent(arguments[c]);return"Minified React error #"+a+"; visit "+b+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}
'use strict';var aa=__nccwpck_require__(522),p=__nccwpck_require__(41),q=Object.assign;function z(a){for(var b="https://reactjs.org/docs/error-decoder.html?invariant="+a,c=1;c<arguments.length;c++)b+="&args[]="+encodeURIComponent(arguments[c]);return"Minified React error #"+a+"; visit "+b+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}
var ba=aa.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,ca=Symbol.for("react.element"),da=Symbol.for("react.portal"),ea=Symbol.for("react.fragment"),ha=Symbol.for("react.strict_mode"),ia=Symbol.for("react.profiler"),ja=Symbol.for("react.provider"),ka=Symbol.for("react.context"),la=Symbol.for("react.server_context"),ma=Symbol.for("react.forward_ref"),na=Symbol.for("react.suspense"),oa=Symbol.for("react.suspense_list"),pa=Symbol.for("react.memo"),qa=Symbol.for("react.lazy"),ra=Symbol.for("react.scope");
Symbol.for("react.debug_trace_mode");var sa=Symbol.for("react.offscreen"),ta=Symbol.for("react.legacy_hidden"),ua=Symbol.for("react.cache");Symbol.for("react.tracing_marker");var va=Symbol.for("react.default_value"),wa=Symbol.iterator;function xa(a){if(null===a||"object"!==typeof a)return null;a=wa&&a[wa]||a["@@iterator"];return"function"===typeof a?a:null}
function ya(a){if(null==a)return null;if("function"===typeof a)return a.displayName||a.name||null;if("string"===typeof a)return a;switch(a){case ea:return"Fragment";case da:return"Portal";case ia:return"Profiler";case ha:return"StrictMode";case na:return"Suspense";case oa:return"SuspenseList";case ua:return"Cache"}if("object"===typeof a)switch(a.$$typeof){case ka:return(a.displayName||"Context")+".Consumer";case ja:return(a._context.displayName||"Context")+".Provider";case ma:var b=a.render;a=a.displayName;
Expand Down Expand Up @@ -33180,10 +33180,10 @@ if (process.env.NODE_ENV === 'production') {

/***/ }),

/***/ 533:
/***/ 522:
/***/ ((module) => {

module.exports = require("next/dist/compiled/react");
module.exports = require("react");

/***/ })

Expand Down
12 changes: 6 additions & 6 deletions packages/next/compiled/react-dom/server.browser.js
Expand Up @@ -21,7 +21,7 @@ if (process.env.NODE_ENV !== "production") {
(function() {
'use strict';

var React = __nccwpck_require__(533);
var React = __nccwpck_require__(522);

var ReactVersion = '18.3.0-experimental-cb5084d1c-20220924';

Expand Down Expand Up @@ -7422,7 +7422,7 @@ exports.version = ReactVersion;
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var aa=__nccwpck_require__(533);function m(a){for(var b="https://reactjs.org/docs/error-decoder.html?invariant="+a,c=1;c<arguments.length;c++)b+="&args[]="+encodeURIComponent(arguments[c]);return"Minified React error #"+a+"; visit "+b+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}
var aa=__nccwpck_require__(522);function m(a){for(var b="https://reactjs.org/docs/error-decoder.html?invariant="+a,c=1;c<arguments.length;c++)b+="&args[]="+encodeURIComponent(arguments[c]);return"Minified React error #"+a+"; visit "+b+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}
var q=Object.prototype.hasOwnProperty,ba=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,ca={},da={};
function ea(a){if(q.call(da,a))return!0;if(q.call(ca,a))return!1;if(ba.test(a))return da[a]=!0;ca[a]=!0;return!1}function t(a,b,c,d,e,g,f){this.acceptsBooleans=2===b||3===b||4===b;this.attributeName=d;this.attributeNamespace=e;this.mustUseProperty=c;this.propertyName=a;this.type=b;this.sanitizeURL=g;this.removeEmptyString=f}var v={},fa="children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ");
fa.push("innerText","textContent");fa.forEach(function(a){v[a]=new t(a,0,!1,a,null,!1,!1)});[["acceptCharset","accept-charset"],["className","class"],["htmlFor","for"],["httpEquiv","http-equiv"]].forEach(function(a){var b=a[0];v[b]=new t(b,1,!1,a[1],null,!1,!1)});["contentEditable","draggable","spellCheck","value"].forEach(function(a){v[a]=new t(a,2,!1,a.toLowerCase(),null,!1,!1)});
Expand Down Expand Up @@ -7532,7 +7532,7 @@ if (process.env.NODE_ENV !== "production") {
(function() {
'use strict';

var React = __nccwpck_require__(533);
var React = __nccwpck_require__(522);

var ReactVersion = '18.3.0-experimental-cb5084d1c-20220924';

Expand Down Expand Up @@ -14925,7 +14925,7 @@ exports.version = ReactVersion;
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var aa=__nccwpck_require__(533);function k(a){for(var b="https://reactjs.org/docs/error-decoder.html?invariant="+a,c=1;c<arguments.length;c++)b+="&args[]="+encodeURIComponent(arguments[c]);return"Minified React error #"+a+"; visit "+b+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var m=null,p=0;
var aa=__nccwpck_require__(522);function k(a){for(var b="https://reactjs.org/docs/error-decoder.html?invariant="+a,c=1;c<arguments.length;c++)b+="&args[]="+encodeURIComponent(arguments[c]);return"Minified React error #"+a+"; visit "+b+" for the full message or use the non-minified dev environment for full errors and additional helpful warnings."}var m=null,p=0;
function q(a,b){if(0!==b.length)if(512<b.length)0<p&&(a.enqueue(new Uint8Array(m.buffer,0,p)),m=new Uint8Array(512),p=0),a.enqueue(b);else{var c=m.length-p;c<b.length&&(0===c?a.enqueue(m):(m.set(b.subarray(0,c),p),a.enqueue(m),b=b.subarray(c)),m=new Uint8Array(512),p=0);m.set(b,p);p+=b.length}}function u(a,b){q(a,b);return!0}function ba(a){m&&0<p&&(a.enqueue(new Uint8Array(m.buffer,0,p)),m=null,p=0)}var ca=new TextEncoder;function v(a){return ca.encode(a)}function x(a){return ca.encode(a)}
function da(a,b){"function"===typeof a.error?a.error(b):a.close()}var y=Object.prototype.hasOwnProperty,ea=/^[:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD][:A-Z_a-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\-.0-9\u00B7\u0300-\u036F\u203F-\u2040]*$/,fa={},ha={};
function ia(a){if(y.call(ha,a))return!0;if(y.call(fa,a))return!1;if(ea.test(a))return ha[a]=!0;fa[a]=!0;return!1}function A(a,b,c,d,e,g,f){this.acceptsBooleans=2===b||3===b||4===b;this.attributeName=d;this.attributeNamespace=e;this.mustUseProperty=c;this.propertyName=a;this.type=b;this.sanitizeURL=g;this.removeEmptyString=f}var B={},ja="children dangerouslySetInnerHTML defaultValue defaultChecked innerHTML suppressContentEditableWarning suppressHydrationWarning style".split(" ");
Expand Down Expand Up @@ -15019,10 +15019,10 @@ a;try{qd(h,a)}catch(w){X(h,w),Y(h,w)}}},cancel:function(){wd(h)}},{highWaterMark

/***/ }),

/***/ 533:
/***/ 522:
/***/ ((module) => {

module.exports = require("next/dist/compiled/react");
module.exports = require("react");

/***/ })

Expand Down

0 comments on commit a50d7f8

Please sign in to comment.