Unverified Commit b2ac41c7 authored by JJ Kasper's avatar JJ Kasper Committed by GitHub

Fix unexpected polyfills in edge-runtime (#45601)

This cuts the edge bundle sizes in half for app dir specifically and
also reduces the size for pages. This also ensures we don't regress in
the future as it stops allowing fallback polyfills from webpack with the
edge runtime which is what let this slip through.

The specific polyfills that were causing bloat in `app-render` were

- `stream-browserify` added `48kB`
- `crypto-browserify` added `355kB`

<details>

<summary>Before</summary>

![next-v13 1 7-canary
5](https://user-images.githubusercontent.com/22380829/216898959-f610aa01-2198-4653-a4bd-8090cf9802aa.png)

</details>

<details>

<summary>After</summary>


![next-on-edge-fixes](https://user-images.githubusercontent.com/22380829/216898986-836804d7-187c-4ae7-93a4-071995c5c87a.png)


</details>
parent c484b73e
...@@ -1863,114 +1863,106 @@ export default async function getBaseWebpackConfig( ...@@ -1863,114 +1863,106 @@ export default async function getBaseWebpackConfig(
}, },
] ]
: []), : []),
...(isEdgeServer || isClient ...(isEdgeServer
? [ ? [
{ {
oneOf: [ resolve: {
{ fallback: {
issuerLayer: WEBPACK_LAYERS.middleware, process: require.resolve('./polyfills/process'),
resolve: {
fallback: {
process: require.resolve('./polyfills/process'),
},
},
},
{
resolve: {
fallback:
config.experimental.fallbackNodePolyfills === false
? {
assert: false,
buffer: false,
constants: false,
crypto: false,
domain: false,
http: false,
https: false,
os: false,
path: false,
punycode: false,
process: false,
querystring: false,
stream: false,
string_decoder: false,
sys: false,
timers: false,
tty: false,
util: false,
vm: false,
zlib: false,
events: false,
setImmediate: false,
}
: {
assert: require.resolve(
'next/dist/compiled/assert'
),
buffer: require.resolve(
'next/dist/compiled/buffer/'
),
constants: require.resolve(
'next/dist/compiled/constants-browserify'
),
crypto: require.resolve(
'next/dist/compiled/crypto-browserify'
),
domain: require.resolve(
'next/dist/compiled/domain-browser'
),
http: require.resolve(
'next/dist/compiled/stream-http'
),
https: require.resolve(
'next/dist/compiled/https-browserify'
),
os: require.resolve(
'next/dist/compiled/os-browserify'
),
path: require.resolve(
'next/dist/compiled/path-browserify'
),
punycode: require.resolve(
'next/dist/compiled/punycode'
),
process: require.resolve('./polyfills/process'),
// Handled in separate alias
querystring: require.resolve(
'next/dist/compiled/querystring-es3'
),
stream: require.resolve(
'next/dist/compiled/stream-browserify'
),
string_decoder: require.resolve(
'next/dist/compiled/string_decoder'
),
sys: require.resolve('next/dist/compiled/util/'),
timers: require.resolve(
'next/dist/compiled/timers-browserify'
),
tty: require.resolve(
'next/dist/compiled/tty-browserify'
),
// Handled in separate alias
// url: require.resolve('url/'),
util: require.resolve('next/dist/compiled/util/'),
vm: require.resolve(
'next/dist/compiled/vm-browserify'
),
zlib: require.resolve(
'next/dist/compiled/browserify-zlib'
),
events: require.resolve(
'next/dist/compiled/events/'
),
setImmediate: require.resolve(
'next/dist/compiled/setimmediate'
),
},
},
}, },
], },
},
]
: isClient
? [
{
resolve: {
fallback:
config.experimental.fallbackNodePolyfills === false
? {
assert: false,
buffer: false,
constants: false,
crypto: false,
domain: false,
http: false,
https: false,
os: false,
path: false,
punycode: false,
process: false,
querystring: false,
stream: false,
string_decoder: false,
sys: false,
timers: false,
tty: false,
util: false,
vm: false,
zlib: false,
events: false,
setImmediate: false,
}
: {
assert: require.resolve('next/dist/compiled/assert'),
buffer: require.resolve('next/dist/compiled/buffer/'),
constants: require.resolve(
'next/dist/compiled/constants-browserify'
),
crypto: require.resolve(
'next/dist/compiled/crypto-browserify'
),
domain: require.resolve(
'next/dist/compiled/domain-browser'
),
http: require.resolve(
'next/dist/compiled/stream-http'
),
https: require.resolve(
'next/dist/compiled/https-browserify'
),
os: require.resolve(
'next/dist/compiled/os-browserify'
),
path: require.resolve(
'next/dist/compiled/path-browserify'
),
punycode: require.resolve(
'next/dist/compiled/punycode'
),
process: require.resolve('./polyfills/process'),
// Handled in separate alias
querystring: require.resolve(
'next/dist/compiled/querystring-es3'
),
stream: require.resolve(
'next/dist/compiled/stream-browserify'
),
string_decoder: require.resolve(
'next/dist/compiled/string_decoder'
),
sys: require.resolve('next/dist/compiled/util/'),
timers: require.resolve(
'next/dist/compiled/timers-browserify'
),
tty: require.resolve(
'next/dist/compiled/tty-browserify'
),
// Handled in separate alias
// url: require.resolve('url/'),
util: require.resolve('next/dist/compiled/util/'),
vm: require.resolve(
'next/dist/compiled/vm-browserify'
),
zlib: require.resolve(
'next/dist/compiled/browserify-zlib'
),
events: require.resolve('next/dist/compiled/events/'),
setImmediate: require.resolve(
'next/dist/compiled/setimmediate'
),
},
},
}, },
] ]
: []), : []),
......
...@@ -10,9 +10,9 @@ import type { ...@@ -10,9 +10,9 @@ import type {
} from '../../../../../types' } from '../../../../../types'
import type { BaseNextRequest } from '../../../../server/base-http' import type { BaseNextRequest } from '../../../../server/base-http'
import type { __ApiPreviewProps } from '../../../../server/api-utils' import type { __ApiPreviewProps } from '../../../../server/api-utils'
import type { ParsedUrlQuery } from 'querystring'
import { format as formatUrl, UrlWithParsedQuery, parse as parseUrl } from 'url' import { format as formatUrl, UrlWithParsedQuery, parse as parseUrl } from 'url'
import { parse as parseQs, ParsedUrlQuery } from 'querystring'
import { normalizeLocalePath } from '../../../../shared/lib/i18n/normalize-locale-path' import { normalizeLocalePath } from '../../../../shared/lib/i18n/normalize-locale-path'
import { getPathMatch } from '../../../../shared/lib/router/utils/path-match' import { getPathMatch } from '../../../../shared/lib/router/utils/path-match'
import { getNamedRouteRegex } from '../../../../shared/lib/router/utils/route-regex' import { getNamedRouteRegex } from '../../../../shared/lib/router/utils/route-regex'
...@@ -292,7 +292,7 @@ export function getUtils({ ...@@ -292,7 +292,7 @@ export function getUtils({
re: { re: {
// Simulate a RegExp match from the \`req.url\` input // Simulate a RegExp match from the \`req.url\` input
exec: (str: string) => { exec: (str: string) => {
const obj = parseQs(str) const obj = Object.fromEntries(new URLSearchParams(str))
const matchesHasLocale = const matchesHasLocale =
i18n && detectedLocale && obj['1'] === detectedLocale i18n && detectedLocale && obj['1'] === detectedLocale
......
(function(){var e={477:function(e){"use strict";e.exports=require("querystring")}};var t={};function __nccwpck_require__(o){var a=t[o];if(a!==undefined){return a.exports}var s=t[o]={exports:{}};var n=true;try{e[o](s,s.exports,__nccwpck_require__);n=false}finally{if(n)delete t[o]}return s.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var o={};!function(){var e=o;var t,a=(t=__nccwpck_require__(477))&&"object"==typeof t&&"default"in t?t.default:t,s=/https?|ftp|gopher|file/;function r(e){"string"==typeof e&&(e=d(e));var t=function(e,t,o){var a=e.auth,s=e.hostname,n=e.protocol||"",p=e.pathname||"",c=e.hash||"",i=e.query||"",u=!1;a=a?encodeURIComponent(a).replace(/%3A/i,":")+"@":"",e.host?u=a+e.host:s&&(u=a+(~s.indexOf(":")?"["+s+"]":s),e.port&&(u+=":"+e.port)),i&&"object"==typeof i&&(i=t.encode(i));var f=e.search||i&&"?"+i||"";return n&&":"!==n.substr(-1)&&(n+=":"),e.slashes||(!n||o.test(n))&&!1!==u?(u="//"+(u||""),p&&"/"!==p[0]&&(p="/"+p)):u||(u=""),c&&"#"!==c[0]&&(c="#"+c),f&&"?"!==f[0]&&(f="?"+f),{protocol:n,host:u,pathname:p=p.replace(/[?#]/g,encodeURIComponent),search:f=f.replace("#","%23"),hash:c}}(e,a,s);return""+t.protocol+t.host+t.pathname+t.search+t.hash}var n="http://",p="w.w",c=n+p,i=/^([a-z0-9.+-]*:\/\/\/)([a-z0-9.+-]:\/*)?/i,u=/https?|ftp|gopher|file/;function h(e,t){var o="string"==typeof e?d(e):e;e="object"==typeof e?r(e):e;var a=d(t),s="";o.protocol&&!o.slashes&&(s=o.protocol,e=e.replace(o.protocol,""),s+="/"===t[0]||"/"===e[0]?"/":""),s&&a.protocol&&(s="",a.slashes||(s=a.protocol,t=t.replace(a.protocol,"")));var p=e.match(i);p&&!a.protocol&&(e=e.substr((s=p[1]+(p[2]||"")).length),/^\/\/[^/]/.test(t)&&(s=s.slice(0,-1)));var f=new URL(e,c+"/"),m=new URL(t,f).toString().replace(c,""),v=a.protocol||o.protocol;return v+=o.slashes||a.slashes?"//":"",!s&&v?m=m.replace(n,v):s&&(m=m.replace(n,"")),u.test(m)||~t.indexOf(".")||"/"===e.slice(-1)||"/"===t.slice(-1)||"/"!==m.slice(-1)||(m=m.slice(0,-1)),s&&(m=s+("/"===m[0]?m.substr(1):m)),m}function l(){}l.prototype.parse=d,l.prototype.format=r,l.prototype.resolve=h,l.prototype.resolveObject=h;var f=/^https?|ftp|gopher|file/,m=/^(.*?)([#?].*)/,v=/^([a-z0-9.+-]*:)(\/{0,3})(.*)/i,_=/^([a-z0-9.+-]*:)?\/\/\/*/i,b=/^([a-z0-9.+-]*:)(\/{0,2})\[(.*)\]$/i;function d(e,t,o){if(void 0===t&&(t=!1),void 0===o&&(o=!1),e&&"object"==typeof e&&e instanceof l)return e;var s=(e=e.trim()).match(m);e=s?s[1].replace(/\\/g,"/")+s[2]:e.replace(/\\/g,"/"),b.test(e)&&"/"!==e.slice(-1)&&(e+="/");var n=!/(^javascript)/.test(e)&&e.match(v),i=_.test(e),u="";n&&(f.test(n[1])||(u=n[1].toLowerCase(),e=""+n[2]+n[3]),n[2]||(i=!1,f.test(n[1])?(u=n[1],e=""+n[3]):e="//"+n[3]),3!==n[2].length&&1!==n[2].length||(u=n[1],e="/"+n[3]));var g,y=(s?s[1]:e).match(/^https?:\/\/[^/]+(:[0-9]+)(?=\/|$)/),w=y&&y[1],C=new l,U="",j="";try{g=new URL(e)}catch(t){U=t,u||o||!/^\/\//.test(e)||/^\/\/.+[@.]/.test(e)||(j="/",e=e.substr(1));try{g=new URL(e,c)}catch(e){return C.protocol=u,C.href=u,C}}C.slashes=i&&!j,C.host=g.host===p?"":g.host,C.hostname=g.hostname===p?"":g.hostname.replace(/(\[|\])/g,""),C.protocol=U?u||null:g.protocol,C.search=g.search.replace(/\\/g,"%5C"),C.hash=g.hash.replace(/\\/g,"%5C");var x=e.split("#");!C.search&&~x[0].indexOf("?")&&(C.search="?"),C.hash||""!==x[1]||(C.hash="#"),C.query=t?a.decode(g.search.substr(1)):C.search.substr(1),C.pathname=j+(n?function(e){return e.replace(/['^|`]/g,(function(e){return"%"+e.charCodeAt().toString(16).toUpperCase()})).replace(/((?:%[0-9A-F]{2})+)/g,(function(e,t){try{return decodeURIComponent(t).split("").map((function(e){var t=e.charCodeAt();return t>256||/^[a-z0-9]$/i.test(e)?e:"%"+t.toString(16).toUpperCase()})).join("")}catch(e){return t}}))}(g.pathname):g.pathname),"about:"===C.protocol&&"blank"===C.pathname&&(C.protocol="",C.pathname=""),U&&"/"!==e[0]&&(C.pathname=C.pathname.substr(1)),u&&!f.test(u)&&"/"!==e.slice(-1)&&"/"===C.pathname&&(C.pathname=""),C.path=C.pathname+C.search,C.auth=[g.username,g.password].map(decodeURIComponent).filter(Boolean).join(":"),C.port=g.port,w&&!C.host.endsWith(w)&&(C.host+=w,C.port=w.slice(1)),C.href=j?""+C.pathname+C.search+C.hash:r(C);var q=/^(file)/.test(C.href)?["host","hostname"]:[];return Object.keys(C).forEach((function(e){~q.indexOf(e)||(C[e]=C[e]||null)})),C}e.parse=d,e.format=r,e.resolve=h,e.resolveObject=function(e,t){return d(h(e,t))},e.Url=l}();module.exports=o})(); (function(){var e={452:function(e){"use strict";e.exports=require("next/dist/compiled/querystring-es3")}};var t={};function __nccwpck_require__(o){var a=t[o];if(a!==undefined){return a.exports}var s=t[o]={exports:{}};var n=true;try{e[o](s,s.exports,__nccwpck_require__);n=false}finally{if(n)delete t[o]}return s.exports}if(typeof __nccwpck_require__!=="undefined")__nccwpck_require__.ab=__dirname+"/";var o={};!function(){var e=o;var t,a=(t=__nccwpck_require__(452))&&"object"==typeof t&&"default"in t?t.default:t,s=/https?|ftp|gopher|file/;function r(e){"string"==typeof e&&(e=d(e));var t=function(e,t,o){var a=e.auth,s=e.hostname,n=e.protocol||"",p=e.pathname||"",c=e.hash||"",i=e.query||"",u=!1;a=a?encodeURIComponent(a).replace(/%3A/i,":")+"@":"",e.host?u=a+e.host:s&&(u=a+(~s.indexOf(":")?"["+s+"]":s),e.port&&(u+=":"+e.port)),i&&"object"==typeof i&&(i=t.encode(i));var f=e.search||i&&"?"+i||"";return n&&":"!==n.substr(-1)&&(n+=":"),e.slashes||(!n||o.test(n))&&!1!==u?(u="//"+(u||""),p&&"/"!==p[0]&&(p="/"+p)):u||(u=""),c&&"#"!==c[0]&&(c="#"+c),f&&"?"!==f[0]&&(f="?"+f),{protocol:n,host:u,pathname:p=p.replace(/[?#]/g,encodeURIComponent),search:f=f.replace("#","%23"),hash:c}}(e,a,s);return""+t.protocol+t.host+t.pathname+t.search+t.hash}var n="http://",p="w.w",c=n+p,i=/^([a-z0-9.+-]*:\/\/\/)([a-z0-9.+-]:\/*)?/i,u=/https?|ftp|gopher|file/;function h(e,t){var o="string"==typeof e?d(e):e;e="object"==typeof e?r(e):e;var a=d(t),s="";o.protocol&&!o.slashes&&(s=o.protocol,e=e.replace(o.protocol,""),s+="/"===t[0]||"/"===e[0]?"/":""),s&&a.protocol&&(s="",a.slashes||(s=a.protocol,t=t.replace(a.protocol,"")));var p=e.match(i);p&&!a.protocol&&(e=e.substr((s=p[1]+(p[2]||"")).length),/^\/\/[^/]/.test(t)&&(s=s.slice(0,-1)));var f=new URL(e,c+"/"),m=new URL(t,f).toString().replace(c,""),v=a.protocol||o.protocol;return v+=o.slashes||a.slashes?"//":"",!s&&v?m=m.replace(n,v):s&&(m=m.replace(n,"")),u.test(m)||~t.indexOf(".")||"/"===e.slice(-1)||"/"===t.slice(-1)||"/"!==m.slice(-1)||(m=m.slice(0,-1)),s&&(m=s+("/"===m[0]?m.substr(1):m)),m}function l(){}l.prototype.parse=d,l.prototype.format=r,l.prototype.resolve=h,l.prototype.resolveObject=h;var f=/^https?|ftp|gopher|file/,m=/^(.*?)([#?].*)/,v=/^([a-z0-9.+-]*:)(\/{0,3})(.*)/i,_=/^([a-z0-9.+-]*:)?\/\/\/*/i,b=/^([a-z0-9.+-]*:)(\/{0,2})\[(.*)\]$/i;function d(e,t,o){if(void 0===t&&(t=!1),void 0===o&&(o=!1),e&&"object"==typeof e&&e instanceof l)return e;var s=(e=e.trim()).match(m);e=s?s[1].replace(/\\/g,"/")+s[2]:e.replace(/\\/g,"/"),b.test(e)&&"/"!==e.slice(-1)&&(e+="/");var n=!/(^javascript)/.test(e)&&e.match(v),i=_.test(e),u="";n&&(f.test(n[1])||(u=n[1].toLowerCase(),e=""+n[2]+n[3]),n[2]||(i=!1,f.test(n[1])?(u=n[1],e=""+n[3]):e="//"+n[3]),3!==n[2].length&&1!==n[2].length||(u=n[1],e="/"+n[3]));var g,y=(s?s[1]:e).match(/^https?:\/\/[^/]+(:[0-9]+)(?=\/|$)/),w=y&&y[1],x=new l,C="",U="";try{g=new URL(e)}catch(t){C=t,u||o||!/^\/\//.test(e)||/^\/\/.+[@.]/.test(e)||(U="/",e=e.substr(1));try{g=new URL(e,c)}catch(e){return x.protocol=u,x.href=u,x}}x.slashes=i&&!U,x.host=g.host===p?"":g.host,x.hostname=g.hostname===p?"":g.hostname.replace(/(\[|\])/g,""),x.protocol=C?u||null:g.protocol,x.search=g.search.replace(/\\/g,"%5C"),x.hash=g.hash.replace(/\\/g,"%5C");var j=e.split("#");!x.search&&~j[0].indexOf("?")&&(x.search="?"),x.hash||""!==j[1]||(x.hash="#"),x.query=t?a.decode(g.search.substr(1)):x.search.substr(1),x.pathname=U+(n?function(e){return e.replace(/['^|`]/g,(function(e){return"%"+e.charCodeAt().toString(16).toUpperCase()})).replace(/((?:%[0-9A-F]{2})+)/g,(function(e,t){try{return decodeURIComponent(t).split("").map((function(e){var t=e.charCodeAt();return t>256||/^[a-z0-9]$/i.test(e)?e:"%"+t.toString(16).toUpperCase()})).join("")}catch(e){return t}}))}(g.pathname):g.pathname),"about:"===x.protocol&&"blank"===x.pathname&&(x.protocol="",x.pathname=""),C&&"/"!==e[0]&&(x.pathname=x.pathname.substr(1)),u&&!f.test(u)&&"/"!==e.slice(-1)&&"/"===x.pathname&&(x.pathname=""),x.path=x.pathname+x.search,x.auth=[g.username,g.password].map(decodeURIComponent).filter(Boolean).join(":"),x.port=g.port,w&&!x.host.endsWith(w)&&(x.host+=w,x.port=w.slice(1)),x.href=U?""+x.pathname+x.search+x.hash:r(x);var q=/^(file)/.test(x.href)?["host","hostname"]:[];return Object.keys(x).forEach((function(e){~q.indexOf(e)||(x[e]=x[e]||null)})),x}e.parse=d,e.format=r,e.resolve=h,e.resolveObject=function(e,t){return d(h(e,t))},e.Url=l}();module.exports=o})();
\ No newline at end of file \ No newline at end of file
...@@ -6,7 +6,6 @@ import type { FontLoaderManifest } from '../build/webpack/plugins/font-loader-ma ...@@ -6,7 +6,6 @@ import type { FontLoaderManifest } from '../build/webpack/plugins/font-loader-ma
// Import builtin react directly to avoid require cache conflicts // Import builtin react directly to avoid require cache conflicts
import React, { use } from 'next/dist/compiled/react' import React, { use } from 'next/dist/compiled/react'
import { NotFound as DefaultNotFound } from '../client/components/error' import { NotFound as DefaultNotFound } from '../client/components/error'
import { nanoid } from 'next/dist/compiled/nanoid/index.cjs'
// this needs to be required lazily so that `next-server` can set // this needs to be required lazily so that `next-server` can set
// the env before we require // the env before we require
...@@ -38,7 +37,6 @@ import { DYNAMIC_ERROR_CODE } from '../client/components/hooks-server-context' ...@@ -38,7 +37,6 @@ import { DYNAMIC_ERROR_CODE } from '../client/components/hooks-server-context'
import { NOT_FOUND_ERROR_CODE } from '../client/components/not-found' import { NOT_FOUND_ERROR_CODE } from '../client/components/not-found'
import { NEXT_DYNAMIC_NO_SSR_CODE } from '../shared/lib/app-dynamic/no-ssr-error' import { NEXT_DYNAMIC_NO_SSR_CODE } from '../shared/lib/app-dynamic/no-ssr-error'
import { HeadManagerContext } from '../shared/lib/head-manager-context' import { HeadManagerContext } from '../shared/lib/head-manager-context'
import { Writable } from 'stream'
import stringHash from 'next/dist/compiled/string-hash' import stringHash from 'next/dist/compiled/string-hash'
import { import {
NEXT_ROUTER_PREFETCH, NEXT_ROUTER_PREFETCH,
...@@ -989,7 +987,11 @@ export async function renderToHTMLOrFlight( ...@@ -989,7 +987,11 @@ export async function renderToHTMLOrFlight(
* that we need to resolve the final metadata. * that we need to resolve the final metadata.
*/ */
const requestId = nanoid(12) const requestId =
process.env.NEXT_RUNTIME === 'edge'
? crypto.randomUUID()
: require('next/dist/compiled/nanoid').nanoid()
const searchParamsProps = { searchParams: query } const searchParamsProps = { searchParams: query }
stripInternalQueries(query) stripInternalQueries(query)
...@@ -1582,17 +1584,18 @@ export async function renderToHTMLOrFlight( ...@@ -1582,17 +1584,18 @@ export async function renderToHTMLOrFlight(
const streamToBufferedResult = async ( const streamToBufferedResult = async (
renderResult: RenderResult renderResult: RenderResult
): Promise<string> => { ): Promise<string> => {
const renderChunks: Buffer[] = [] const renderChunks: string[] = []
const writable = new Writable({
write(chunk, _encoding, callback) { const writable = {
renderChunks.push(chunk) write(chunk: any) {
callback() renderChunks.push(decodeText(chunk))
}, },
}) end() {},
await renderResult.pipe(writable) destroy() {},
return Buffer.concat(renderChunks).toString() }
await renderResult.pipe(writable as any)
return renderChunks.join('')
} }
// Handle Flight render request. This is only used when client-side navigating. E.g. when you `router.push('/dashboard')` or `router.reload()`. // Handle Flight render request. This is only used when client-side navigating. E.g. when you `router.push('/dashboard')` or `router.reload()`.
const generateFlight = async (): Promise<RenderResult> => { const generateFlight = async (): Promise<RenderResult> => {
// TODO-APP: throw on invalid flightRouterState // TODO-APP: throw on invalid flightRouterState
......
...@@ -30,7 +30,6 @@ import type { PayloadOptions } from './send-payload' ...@@ -30,7 +30,6 @@ import type { PayloadOptions } from './send-payload'
import type { PrerenderManifest } from '../build' import type { PrerenderManifest } from '../build'
import type { FontLoaderManifest } from '../build/webpack/plugins/font-loader-manifest-plugin' import type { FontLoaderManifest } from '../build/webpack/plugins/font-loader-manifest-plugin'
import { parse as parseQs } from 'querystring'
import { format as formatUrl, parse as parseUrl } from 'url' import { format as formatUrl, parse as parseUrl } from 'url'
import { getRedirectStatus } from '../lib/redirect-status' import { getRedirectStatus } from '../lib/redirect-status'
import { isEdgeRuntime } from '../lib/is-edge-runtime' import { isEdgeRuntime } from '../lib/is-edge-runtime'
...@@ -493,7 +492,9 @@ export default abstract class Server<ServerOptions extends Options = Options> { ...@@ -493,7 +492,9 @@ export default abstract class Server<ServerOptions extends Options = Options> {
// Parse the querystring ourselves if the user doesn't handle querystring parsing // Parse the querystring ourselves if the user doesn't handle querystring parsing
if (typeof parsedUrl.query === 'string') { if (typeof parsedUrl.query === 'string') {
parsedUrl.query = parseQs(parsedUrl.query) parsedUrl.query = Object.fromEntries(
new URLSearchParams(parsedUrl.query)
)
} }
// in minimal mode we detect RSC revalidate if the .rsc // in minimal mode we detect RSC revalidate if the .rsc
// path is requested // path is requested
......
...@@ -40,7 +40,11 @@ function defaultLoader({ ...@@ -40,7 +40,11 @@ function defaultLoader({
) )
} }
if (process.env.NODE_ENV !== 'test') { if (
process.env.NODE_ENV !== 'test' &&
// micromatch isn't compatible with edge runtime
process.env.NEXT_RUNTIME !== 'edge'
) {
// We use dynamic require because this should only error in development // We use dynamic require because this should only error in development
const { hasMatch } = require('./match-remote-pattern') const { hasMatch } = require('./match-remote-pattern')
if (!hasMatch(config.domains, config.remotePatterns, parsedSrc)) { if (!hasMatch(config.domains, config.remotePatterns, parsedSrc)) {
......
...@@ -1358,7 +1358,14 @@ externals['native-url'] = 'next/dist/compiled/native-url' ...@@ -1358,7 +1358,14 @@ externals['native-url'] = 'next/dist/compiled/native-url'
export async function ncc_native_url(task, opts) { export async function ncc_native_url(task, opts) {
await task await task
.source(relative(__dirname, require.resolve('native-url'))) .source(relative(__dirname, require.resolve('native-url')))
.ncc({ packageName: 'native-url', externals, target: 'es5' }) .ncc({
packageName: 'native-url',
externals: {
...externals,
querystring: 'next/dist/compiled/querystring-es3',
},
target: 'es5',
})
.target('src/compiled/native-url') .target('src/compiled/native-url')
} }
// eslint-disable-next-line camelcase // eslint-disable-next-line camelcase
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment