-
Notifications
You must be signed in to change notification settings - Fork 26.1k
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
refactor(ts): type fastRefresh
#62848
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
balazsorban44
requested review from
timneutkens,
ijjk,
shuding,
huozhi,
feedthejim,
ztanner and
wyattjoh
as code owners
March 4, 2024 23:34
Stats from current PRDefault BuildGeneral
Client Bundles (main, webpack)
Legacy Client Bundles (polyfills)
Client Pages
Client Build Manifests
Rendered Page Sizes
Edge SSR bundle Size
Middleware size
Next Runtimes
build cache
Diff detailsDiff for middleware.jsDiff too large to display Diff for edge-ssr.jsDiff too large to display Diff for 2453-HASH.jsDiff too large to display Diff for main-HASH.jsDiff too large to display Diff for pages-turbo...time.prod.jsDiff too large to display Diff for pages.runtime.dev.js@@ -14,7 +14,7 @@ Read more: https://nextjs.org/docs/messages/${r}`};function e3(e,t,r){let{destin
`+i.join(" and ")+"\nSee more info here: https://nextjs.org/docs/messages/invalid-redirect-gssp")}async function e2(n,s,a,i,l,d){var u,c,p;let h,m,f,g;(0,x.gk)({req:n},"cookies",(c=n.headers,function(){let{cookie:e}=c;if(!e)return{};let{parse:t}=r("./dist/compiled/cookie/index.js");return t(Array.isArray(e)?e.join("; "):e)}));let v={};if(v.assetQueryString=l.dev&&l.assetQueryString||"",l.dev&&!v.assetQueryString){let e=(n.headers["user-agent"]||"").toLowerCase();e.includes("safari")&&!e.includes("chrome")&&(v.assetQueryString=`?ts=${Date.now()}`)}l.deploymentId&&(v.assetQueryString+=`${v.assetQueryString?"&":"?"}dpl=${l.deploymentId}`),i=Object.assign({},i);let{err:b,dev:w=!1,ampPath:S="",pageConfig:R={},buildManifest:T,reactLoadableManifest:E,ErrorDebug:N,getStaticProps:I,getStaticPaths:k,getServerSideProps:M,isDataReq:q,params:D,previewProps:F,basePath:U,images:Q,runtime:K,isExperimentalCompile:ee,swrDelta:er}=l,{App:ea}=d,ei=v.assetQueryString,el=d.Document,ed=l.Component,ef=!!i.__nextFallback,eg=i.__nextNotFoundSrcPage;!function(e){for(let t of eI)delete e[t]}(i);let ev=!!I,ey=ev&&l.nextExport,ex=ea.getInitialProps===ea.origGetInitialProps,eb=!!(null==ed?void 0:ed.getInitialProps),ew=null==ed?void 0:ed.unstable_scriptLoader,eS=J(a),eP="/_error"===a&&ed.getInitialProps===ed.origGetInitialProps;l.nextExport&&eb&&!eP&&t(`Detected getInitialProps on page '${a}' while running export. It's recommended to use getStaticProps which has a more correct behavior for static exporting.
Read more: https://nextjs.org/docs/messages/get-initial-props-export`);let e_=!eb&&ex&&!ev&&!M;if(e_&&!w&&ee&&(s.setHeader("Cache-Control",function({revalidate:e,swrDelta:t}){let r=t?`stale-while-revalidate=${t}`:"stale-while-revalidate";return 0===e?"private, no-cache, no-store, max-age=0, must-revalidate":"number"==typeof e?`s-maxage=${e}, ${r}`:`s-maxage=${j.BR}, ${r}`}({revalidate:!1,swrDelta:er})),e_=!1),eb&&ev)throw Error(j.wh+` ${a}`);if(eb&&M)throw Error(j.Wo+` ${a}`);if(M&&ev)throw Error(j.oL+` ${a}`);if(M&&"export"===l.nextConfigOutput)throw Error('getServerSideProps cannot be used with "output: export". See more info here: https://nextjs.org/docs/advanced-features/static-html-export');if(k&&!eS)throw Error(`getStaticPaths is only allowed for dynamic SSG pages and was found on '${a}'.
Read more: https://nextjs.org/docs/messages/non-dynamic-getstaticpaths-usage`);if(k&&!ev)throw Error(`getStaticPaths was added without a getStaticProps in ${a}. Without getStaticProps, getStaticPaths does nothing`);if(ev&&eS&&!k)throw Error(`getStaticPaths is required for dynamic SSG pages and is missing for '${a}'.
-Read more: https://nextjs.org/docs/messages/invalid-getstaticpaths-value`);let ej=l.resolvedAsPath||n.url;if(w){let{isValidElementType:e}=r("./dist/compiled/react-is/index.js");if(!e(ed))throw Error(`The default export is not a React Component in page: "${a}"`);if(!e(ea))throw Error('The default export is not a React Component in page: "/_app"');if(!e(el))throw Error('The default export is not a React Component in page: "/_document"');if((e_||ef)&&(i={...i.amp?{amp:i.amp}:{}},ej=`${a}${n.url.endsWith("/")&&"/"!==a&&!eS?"/":""}`,n.url=a),"/404"===a&&(eb||M))throw Error(`\`pages/404\` ${j.Ei}`);if(C.Er.includes(a)&&(eb||M))throw Error(`\`pages${a}\` ${j.Ei}`)}for(let e of["getStaticProps","getServerSideProps","getStaticPaths"])if(null==ed?void 0:ed[e])throw Error(`page ${a} ${e} ${j.lk}`);await H.preloadAll(),(ev||M)&&!ef&&F&&(f=!1!==(h=e(n,s,F)));let eC=!!(M||eb||!ex&&!ev||ee),eR=new e0(a,i,ej,{isFallback:ef},eC,U,l.locale,l.locales,l.defaultLocale,l.domainLocales,f,et(n,"isLocaleDomain")),eT={back(){eR.back()},forward(){eR.forward()},refresh(){eR.reload()},push(e,t){let{scroll:r}=void 0===t?{}:t;eR.push(e,void 0,{scroll:r})},replace(e,t){let{scroll:r}=void 0===t?{}:t;eR.replace(e,void 0,{scroll:r})},prefetch(e){eR.prefetch(e)}},eE={},eN=(0,_.createStyleRegistry)(),eO={ampFirst:!0===R.amp,hasQuery:!!i.amp,hybrid:"hybrid"===R.amp},eM=function(e){let{ampFirst:t=!1,hybrid:r=!1,hasQuery:n=!1}=void 0===e?{}:e;return t||r&&n}(eO),eD=function(e){void 0===e&&(e=!1);let t=[(0,y.jsx)("meta",{charSet:"utf-8"})];return e||t.push((0,y.jsx)("meta",{name:"viewport",content:"width=device-width"})),t}(eM),eF=[],eU={};ew&&(eU.beforeInteractive=[].concat(ew()).filter(e=>"beforeInteractive"===e.props.strategy).map(e=>e.props));let eJ=({children:e})=>{var t;return(0,y.jsx)(eW.Provider,{value:eT,children:(0,y.jsx)(ek.Provider,{value:eR.isReady&&eR.query?(t=eR.asPath,new URL(t,"http://n").searchParams):new URLSearchParams,children:(0,y.jsx)(eB,{router:eR,isAutoExport:e_,children:(0,y.jsx)(eq.Provider,{value:function(e){if(!e.isReady||!e.query)return null;let t={},r=function(e){let{parameterizedRoute:t,groups:r}=function(e){let t=em(e).slice(1).split("/"),r={},n=1;return{parameterizedRoute:t.map(e=>{let t=W.find(t=>e.startsWith(t)),o=e.match(/\[((?:\[.*\])|.+)\]/);if(t&&o){let{key:e,optional:s,repeat:a}=ez(o[1]);return r[e]={pos:n++,repeat:a,optional:s},"/"+eH(t)+"([^/]+?)"}if(!o)return"/"+eH(e);{let{key:e,repeat:t,optional:s}=ez(o[1]);return r[e]={pos:n++,repeat:t,optional:s},t?s?"(?:/(.+?))?":"/(.+?)":"/([^/]+?)"}}).join(""),groups:r}}(e);return{re:RegExp("^"+t+"(?:/)?$"),groups:r}}(e.pathname),n=Object.keys(r.groups);for(let r of n)t[r]=e.query[r];return t}(eR),children:(0,y.jsx)(z.Provider,{value:eR,children:(0,y.jsx)(L.Provider,{value:eO,children:(0,y.jsx)(O.Provider,{value:{updateHead:e=>{eD=e},updateScripts:e=>{eE=e},scripts:eU,mountedInstances:new Set},children:(0,y.jsx)(A.Provider,{value:e=>eF.push(e),children:(0,y.jsx)(_.StyleRegistry,{registry:eN,children:(0,y.jsx)(eL.Provider,{value:Q,children:e})})})})})})})})})})},eG=()=>null,eV=({children:e})=>(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(eG,{}),(0,y.jsx)(eJ,{children:(0,y.jsxs)(y.Fragment,{children:[w?(0,y.jsxs)(y.Fragment,{children:[e,(0,y.jsx)(eG,{})]}):e,(0,y.jsx)(eG,{})]})})]}),eY={err:b,req:e_?void 0:n,res:e_?void 0:s,pathname:a,query:i,asPath:ej,locale:l.locale,locales:l.locales,defaultLocale:l.defaultLocale,AppTree:e=>(0,y.jsx)(eV,{children:e1(ea,ed,{...e,router:eR})}),defaultGetInitialProps:async(e,t={})=>{let{html:r,head:n}=await e.renderPage({enhanceApp:e=>t=>(0,y.jsx)(e,{...t})}),o=eN.styles({nonce:t.nonce});return eN.flush(),{html:r,head:n,styles:o}}},e2=!ev&&(l.nextExport||w&&(e_||ef)),e8=()=>{let e=eN.styles();return eN.flush(),(0,y.jsx)(y.Fragment,{children:e})};if(m=await X(ea,{AppTree:eY.AppTree,Component:ed,router:eR,ctx:eY}),(ev||M)&&f&&(m.__N_PREVIEW=!0),ev&&(m[C.NO]=!0),ev&&!ef){let e,t;try{e=await (0,eo.getTracer)().trace(es.xj.getStaticProps,{spanName:`getStaticProps ${a}`,attributes:{"next.route":a}},()=>I({...eS?{params:i}:void 0,...f?{draftMode:!0,preview:!0,previewData:h}:void 0,locales:l.locales,locale:l.locale,defaultLocale:l.defaultLocale}))}catch(e){throw e&&"ENOENT"===e.code&&delete e.code,e}if(null==e)throw Error(j.q6);let r=Object.keys(e).filter(e=>"revalidate"!==e&&"props"!==e&&"redirect"!==e&&"notFound"!==e);if(r.includes("unstable_revalidate"))throw Error(j.Eo);if(r.length)throw Error(e4("getStaticProps",r));if(void 0!==e.notFound&&void 0!==e.redirect)throw Error(`\`redirect\` and \`notFound\` can not both be returned from ${ev?"getStaticProps":"getServerSideProps"} at the same time. Page: ${a}
+Read more: https://nextjs.org/docs/messages/invalid-getstaticpaths-value`);let ej=l.resolvedAsPath||n.url;if(w){let{isValidElementType:e}=r("./dist/compiled/react-is/index.js");if(!e(ed))throw Error(`The default export is not a React Component in page: "${a}"`);if(!e(ea))throw Error('The default export is not a React Component in page: "/_app"');if(!e(el))throw Error('The default export is not a React Component in page: "/_document"');if((e_||ef)&&(i={...i.amp?{amp:i.amp}:{}},ej=`${a}${n.url.endsWith("/")&&"/"!==a&&!eS?"/":""}`,n.url=a),"/404"===a&&(eb||M))throw Error(`\`pages/404\` ${j.Ei}`);if(C.Er.includes(a)&&(eb||M))throw Error(`\`pages${a}\` ${j.Ei}`)}for(let e of["getStaticProps","getServerSideProps","getStaticPaths"])if(null==ed?void 0:ed[e])throw Error(`page ${a} ${e} ${j.lk}`);await H.preloadAll(),(ev||M)&&!ef&&F&&(f=!1!==(h=e(n,s,F)));let eC=!!(M||eb||!ex&&!ev||ee),eR=new e0(a,i,ej,{isFallback:ef},eC,U,l.locale,l.locales,l.defaultLocale,l.domainLocales,f,et(n,"isLocaleDomain")),eT={back(){eR.back()},forward(){eR.forward()},refresh(){eR.reload()},fastRefresh(){},push(e,t){let{scroll:r}=void 0===t?{}:t;eR.push(e,void 0,{scroll:r})},replace(e,t){let{scroll:r}=void 0===t?{}:t;eR.replace(e,void 0,{scroll:r})},prefetch(e){eR.prefetch(e)}},eE={},eN=(0,_.createStyleRegistry)(),eO={ampFirst:!0===R.amp,hasQuery:!!i.amp,hybrid:"hybrid"===R.amp},eM=function(e){let{ampFirst:t=!1,hybrid:r=!1,hasQuery:n=!1}=void 0===e?{}:e;return t||r&&n}(eO),eD=function(e){void 0===e&&(e=!1);let t=[(0,y.jsx)("meta",{charSet:"utf-8"})];return e||t.push((0,y.jsx)("meta",{name:"viewport",content:"width=device-width"})),t}(eM),eF=[],eU={};ew&&(eU.beforeInteractive=[].concat(ew()).filter(e=>"beforeInteractive"===e.props.strategy).map(e=>e.props));let eJ=({children:e})=>{var t;return(0,y.jsx)(eW.Provider,{value:eT,children:(0,y.jsx)(ek.Provider,{value:eR.isReady&&eR.query?(t=eR.asPath,new URL(t,"http://n").searchParams):new URLSearchParams,children:(0,y.jsx)(eB,{router:eR,isAutoExport:e_,children:(0,y.jsx)(eq.Provider,{value:function(e){if(!e.isReady||!e.query)return null;let t={},r=function(e){let{parameterizedRoute:t,groups:r}=function(e){let t=em(e).slice(1).split("/"),r={},n=1;return{parameterizedRoute:t.map(e=>{let t=W.find(t=>e.startsWith(t)),o=e.match(/\[((?:\[.*\])|.+)\]/);if(t&&o){let{key:e,optional:s,repeat:a}=ez(o[1]);return r[e]={pos:n++,repeat:a,optional:s},"/"+eH(t)+"([^/]+?)"}if(!o)return"/"+eH(e);{let{key:e,repeat:t,optional:s}=ez(o[1]);return r[e]={pos:n++,repeat:t,optional:s},t?s?"(?:/(.+?))?":"/(.+?)":"/([^/]+?)"}}).join(""),groups:r}}(e);return{re:RegExp("^"+t+"(?:/)?$"),groups:r}}(e.pathname),n=Object.keys(r.groups);for(let r of n)t[r]=e.query[r];return t}(eR),children:(0,y.jsx)(z.Provider,{value:eR,children:(0,y.jsx)(L.Provider,{value:eO,children:(0,y.jsx)(O.Provider,{value:{updateHead:e=>{eD=e},updateScripts:e=>{eE=e},scripts:eU,mountedInstances:new Set},children:(0,y.jsx)(A.Provider,{value:e=>eF.push(e),children:(0,y.jsx)(_.StyleRegistry,{registry:eN,children:(0,y.jsx)(eL.Provider,{value:Q,children:e})})})})})})})})})})},eG=()=>null,eV=({children:e})=>(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(eG,{}),(0,y.jsx)(eJ,{children:(0,y.jsxs)(y.Fragment,{children:[w?(0,y.jsxs)(y.Fragment,{children:[e,(0,y.jsx)(eG,{})]}):e,(0,y.jsx)(eG,{})]})})]}),eY={err:b,req:e_?void 0:n,res:e_?void 0:s,pathname:a,query:i,asPath:ej,locale:l.locale,locales:l.locales,defaultLocale:l.defaultLocale,AppTree:e=>(0,y.jsx)(eV,{children:e1(ea,ed,{...e,router:eR})}),defaultGetInitialProps:async(e,t={})=>{let{html:r,head:n}=await e.renderPage({enhanceApp:e=>t=>(0,y.jsx)(e,{...t})}),o=eN.styles({nonce:t.nonce});return eN.flush(),{html:r,head:n,styles:o}}},e2=!ev&&(l.nextExport||w&&(e_||ef)),e8=()=>{let e=eN.styles();return eN.flush(),(0,y.jsx)(y.Fragment,{children:e})};if(m=await X(ea,{AppTree:eY.AppTree,Component:ed,router:eR,ctx:eY}),(ev||M)&&f&&(m.__N_PREVIEW=!0),ev&&(m[C.NO]=!0),ev&&!ef){let e,t;try{e=await (0,eo.getTracer)().trace(es.xj.getStaticProps,{spanName:`getStaticProps ${a}`,attributes:{"next.route":a}},()=>I({...eS?{params:i}:void 0,...f?{draftMode:!0,preview:!0,previewData:h}:void 0,locales:l.locales,locale:l.locale,defaultLocale:l.defaultLocale}))}catch(e){throw e&&"ENOENT"===e.code&&delete e.code,e}if(null==e)throw Error(j.q6);let r=Object.keys(e).filter(e=>"revalidate"!==e&&"props"!==e&&"redirect"!==e&&"notFound"!==e);if(r.includes("unstable_revalidate"))throw Error(j.Eo);if(r.length)throw Error(e4("getStaticProps",r));if(void 0!==e.notFound&&void 0!==e.redirect)throw Error(`\`redirect\` and \`notFound\` can not both be returned from ${ev?"getStaticProps":"getServerSideProps"} at the same time. Page: ${a}
See more info here: https://nextjs.org/docs/messages/gssp-mixed-not-found-redirect`);if("notFound"in e&&e.notFound){if("/404"===a)throw Error('The /404 page can not return notFound in "getStaticProps", please remove it to continue!');v.isNotFound=!0}if("redirect"in e&&e.redirect&&"object"==typeof e.redirect){if(e3(e.redirect,n,"getStaticProps"),ey)throw Error(`\`redirect\` can not be returned from getStaticProps during prerendering (${n.url})
See more info here: https://nextjs.org/docs/messages/gsp-redirect-during-prerender`);e.props={__N_REDIRECT:e.redirect.destination,__N_REDIRECT_STATUS:en(e.redirect)},void 0!==e.redirect.basePath&&(e.props.__N_REDIRECT_BASE_PATH=e.redirect.basePath),v.isRedirect=!0}if((w||ey)&&!v.isNotFound&&!$(a,"getStaticProps",e.props))throw Error("invariant: getStaticProps did not return valid props. Please report this.");if("revalidate"in e){if(e.revalidate&&"export"===l.nextConfigOutput)throw Error('ISR cannot be used with "output: export". See more info here: https://nextjs.org/docs/advanced-features/static-html-export');if("number"==typeof e.revalidate){if(Number.isInteger(e.revalidate)){if(e.revalidate<=0)throw Error(`A page's revalidate option can not be less than or equal to zero for ${n.url}. A revalidate option of zero means to revalidate after _every_ request, and implies stale data cannot be tolerated. Diff for pages.runtime.prod.jsDiff too large to display |
Tests Passed |
huozhi
approved these changes
Mar 7, 2024
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Separated from #62815
Instead of
@ts-ignore
ing this internal method and making it harder for ourselves to use, we can type it correctly and add the@internal
directive that will make sure its type is not emitted to userland. Same behavior, but we get type-hints.Before:
After:
Userland, still no suggestion:
Closes NEXT-2698
Slack thread