- 29 Feb, 2024 5 commits
- 28 Feb, 2024 22 commits
-
-
Max Leiter authored
### What? Backports some Server Action changes from Shu to 14.1.1. [Improve the Server Actions SWC transform ](https://github.com/vercel/next.js/pull/62655/commits/bf6460e985c0ff8e41c03e000cbcb2638bcf99c7) [Fix Server Reference being double registered](https://github.com/vercel/next.js/pull/62655/commits/ef81b1099856bc7918dfa39e6d272cce53451eaf) [Improve the Server Actions SWC transform (part 2)](https://github.com/vercel/next.js/pull/62655/commits/6e59c222a84f48edfc958d3327eb5448431e7784) [Fix module-level Server Action creation with closure-closed values](https://github.com/vercel/next.js/pull/62655/commits/51c6a07ec6a373eca3425ef565a53f4105112099) [Rename internal utility naming for clarification](https://github.com/vercel/next.js/pull/62655/commits/00d8e6e0612b7afddbce5f944a7330413e548871) ### Why? ### How? --------- Co-authored-by:
Shu Ding <g@shud.in> Co-authored-by:
JJ Kasper <jj@jjsweb.site>
-
Jiachi Liu authored
Backport metadata fixes #61898 #62109 #62615 Closes NEXT-2641
-
Ethan Arrowood authored
### What? In today's implementation, requests that don't end in `.rsc` are getting the data request query. We need to remove this toggle to prevent them from 500'ing. ### Why? The invariant triggered was: https://github.com/vercel/next.js/blob/212553958c671ea1f71d96fbc97ea4b9e5019bf3/packages/next/src/server/base-server.ts#L2838-L2842 Crawling up the code, the conditional: https://github.com/vercel/next.js/blob/212553958c671ea1f71d96fbc97ea4b9e5019bf3/packages/next/src/server/base-server.ts#L2815 must be `true`. The variable `isDataReq` is set here: https://github.com/vercel/next.js/blob/212553958c671ea1f71d96fbc97ea4b9e5019bf3/packages/next/src/server/base-server.ts#L1833-L1839 This conditional expression is a bit complex, but it simplifies down to: - `isDataReq` is `true` when (TODO) - `isDataReq` is `false` when (TODO) ### How? Closes NEXT-2341 Fixes #61377 Tested manually by: - Building and packaging this branch locally - Deploying tarball and then depending on it as the Next.js version for an example app similar to the one reported by #61377 - Inspecting console for 500 errors. --------- Co-authored-by:
JJ Kasper <jj@jjsweb.site> Co-authored-by:
Zack Tanner <zacktanner@gmail.com>
-
Steven authored
The `process/browser` lib was imported and being transformed, but `process.browser = true` turns to `true = true` that causes the compilation error, we need to exclude them from certain compilation layers - Fixes https://github.com/vercel/next.js/issues/61116 Closes NEXT-2410 Closes NEXT-2328 --------- Co-authored-by:
Jiachi Liu <inbox@huozhi.im>
-
Jiachi Liu authored
We have a modularize imports config for `next/server` before, which will transform the `next/server` imports to directly import from the actual file, for instance: `import { NextRequest } from 'next/server'` will become `import { NextRequest } from 'next/dist/server/web/exports/next-request'`, where the NextRequest is exported as default export. This is fine in most case until you're using a ESM pkg, then it will be resolved as `{ default: NextRequest }` according to the spec. Since it's a ESM import to a CJS module in `next/dist`. Since we already have the ESM alias introduced in #59852 , this can handle the case more properly. Remove the modularize imports config for `next/server`, use the ESM api alias instead. Migrate the cjs optimizer tests from middleware to a separate endpoint `/cjs/server`. As now ESM imports for next/server are not going to get tree-shaken in dev, but since we don't have image response there it's still fine. Closes NEXT-2376 Closes NEXT-2374 -
JJ Kasper authored
This ensures we don't do un-necessary IPC calls during image optimizing and leverage the internal request handler for fetching internal static images/resources. x-ref: https://github.com/vercel/next.js/issues/58248 Closes NEXT-2318
-
Steven authored
This PR is refactoring only and doesn't change the logic, therefore no tests were added. The improvement here is readability: - separate functions to fetch external vs internal image (in the future, we could improve perf of internal image routing) - types of the arguments are more specific (rather than passing in complete NextConfig) > Note: Its easier to review with whitespace hidden: https://github.com/vercel/next.js/pull/61172/files?w=1
-
Steven authored
This PR adds a warning when attempting to optimize an animated image. ```jsx <Image src="/image.gif" /> ``` The warning looks like the following: ``` The requested resource "/image.gif" is an animated image so it will not be optimized. Consider adding the "unoptimized" property to the <Image>. ``` To remove the warning, add the `unoptimized` prop. ```jsx <Image src="/image.gif" unoptimized /> ``` We don't attempt to optimized animated images because it can be very slow (30+ seconds) and sometimes deoptimizeds (the output is larger than the input) so its best to serve the animated image as-is. Closes NEXT-2199
-
Balázs Orbán authored
We should treat the warning for CSR bailout the same as the hard-error, and show the stack trace for either case. It might be useful to track down the source of this warning. We have the stack info already, but we only showed it during the error logging. We should show it for warnings too. This is similar to #61200 Closes NEXT-2624
-
Jiachi Liu authored
Disable swc transform optimizer for node_modules in browser layer of app router bundles Fixes #61858 Fixes #60644 Fixes #60920 Fixes #61740 Closes NEXT-2418 In browser there could be not only one runtime, it could have both js worker and browser. In js worker the `typeof window` is not as same as in browser, so disabling the swc optimizer which will replace the code. Leave the condition as it as.
-
Donny/강동윤 authored
### What? Patch cjs finder to detect `exports.foo` (instead of module.exports) ### Why? This causes an issue for `react.production.min.js`. x-ref: https://vercel.slack.com/archives/C02HY34AKME/p1707343215879979 ### How? Closes PACK-2443
-
Jiachi Liu authored
### What Exclude precompiled react packages from browser layer loaders coverage. ### Why Since we're transpiling all the browser layer code now after #59569, then SWC will also compile react. But when it compiles `react.production.min.js` it gives me with the code and ESM helper inserted ```js import { _ as _type_of } from "@swc/helpers/_/_type_of"; // This is not correct var l = Symbol.for("react.element"), n = Symbol.for("react.portal"), p = Symbol.for("react.fragment"), q = Sym bol.for("react.strict_mode"), r = Symbol.for("react.profiler"), t = Symbol.for("react.provider"), u = Symbol.f ``` This makes bundler think it's a ESM package but actually it's CJS, which converts the module into `{ default: .., __esModule }` instead of the original react module. When you're using `React.useEffect` or other API through namespace import (`import * as React from 'react'`), this will break the module exports check in bundling as the property doesn't directly attached to the module now. This PR disabled the transform for precompiled react packages now and will see the deeper issue in next-swc side later. Fixes #60890 Fixes #61185 Closes NEXT-2362 -
Jiachi Liu authored
-
JJ Kasper authored
-
JJ Kasper authored
-
Zack Tanner authored
When the popstate action is fired (as is the case in a browser back button), if the page you're going back to has missing cache node data, the router will crash. Almost all router actions will suspend at the app-router level with the exception of `ACTION_RESTORE`. This was to address an issue where suspending in the router would add enough delay for browser scroll restoration behavior not to work. As a result, when going back to the page with missing data, app-router wouldn't suspend but layout-router would suspend on the missing data while triggering a lazy fetch. We trigger a server-patch with the applied lazy data, but when React replays the render, it will replay the branch without the cache node data applied. This results in the router getting caught in a loop of suspending, applying the cache node, replaying the branch without the cache node, and eventually crashing due to an error thrown by React to prevent re-suspending indefinitely. This adds a property to the cache node to signal if the lazy data has been resolved. If it has been, we won't call the server patch action again. Fixes #61336 Closes NEXT-2438
-
Zack Tanner authored
### What Client-side transitioning to a page that triggered a loading boundary with async metadata would cause the transition to stall, potentially getting stuck in a refetch loop. ### Why In layout-router, we trigger a "lazy fetch" when we encounter a segment that we don't have cache nodes for. This calls out to the server and suspends until the data fetch is resolved, and applied to the router tree. However after suspending but before updating the client router, we set `childNode.lazyData` to null. When we unsuspend from the server patch action, `childNode.rsc` might still be missing and clearing `lazyData` means we've blown away the reference to the fetch we already had pending, triggering a refetch loop. ### How This removes the logic that mutates the cache node in render, as this is not concurrent safe, and doesn't appear to be needed for anything. Fixes #61117 Closes NEXT-2361 --------- Co-authored-by:Jiachi Liu <inbox@huozhi.im>
-
Zack Tanner authored
Reverts changes from #61173 & #60240 (while leaving the tests that were added). There are too many spots where considering `/default` routes as pages needs to be carefully considered in different runtimes, and it turns out that it's not actually needed to handle the case that it was originally added for. I confirmed that the test that added the case it was intended to fix (`parallel-routes-catchall-default`, along with the unit tests in `normalize-catchall-routes`) are still passing as expected.
-
Willi#m ⬣ authored
fix parallel route top-level catch-all normalization logic to support nested explicit (non-catchall) slot routes (#60776) Fix NEXT-2165 ### What? Addresses the limitation of #60240, where a dummy `default` file is required in parallel route child slot to prevent errors in dev server rendering (`TypeError: Cannot read properties of undefined (reading 'clientModules')`) as well as errors in build and deploy (`Error: ENOENT: no such file or directory, lstat ‘/vercel/path0/.next/server/app/parallel-route/[section]/@part/[partSlug]/page_client-reference-manifest.js’`) Without the `default.tsx`, builds and deployments will fail with: <img width="956" alt="CleanShot 2024-01-18 at 02 12 36@2x" src="https://github.com/vercel/next.js/assets/179761/80ba61bd-6ec0-4b16-a393-dc9375227e19"> local dev server will also crash with: <img width="986" alt="CleanShot 2024-01-18 at 02 13 19@2x" src="https://github.com/vercel/next.js/assets/179761/cc500a32-b2f8-47b4-999e-e57cf5141b2f"> > TypeError: Cannot read properties of undefined (reading 'clientModules') ### Why? Since `default.tsx` is not a compulsory when you have slot that are specific and ends with a dynamic route segment, this PR extends support so that it is possible mixing catch-all routes with specific non-catchall routes without requiring an additional `default.tsx` . This PR will allow the following test cases to pass: ``` it('should not add the catch-all route to segments that have a more specific [dynamicRoute]', () => { const appPaths = { '/': ['/page'], '/[[...catchAll]]': ['/[[...catchAll]]/page'], '/nested/[foo]/[bar]/default': [ '/nested/[foo]/[bar]/default', '/nested/[foo]/[bar]/@slot0/default', '/nested/[foo]/[bar]/@slot2/default', ], '/nested/[foo]/[bar]': [ '/nested/[foo]/[bar]/@slot0/page', '/nested/[foo]/[bar]/@slot1/page', ], '/nested/[foo]/[bar]/[baz]': [ '/nested/[foo]/[bar]/@slot0/[baz]/page', '/nested/[foo]/[bar]/@slot1/[baz]/page', ], '/[locale]/nested/[foo]/[bar]/[baz]/[qux]': [ '/[locale]/nested/[foo]/[bar]/@slot1/[baz]/[qux]/page', ], } const initialAppPaths = JSON.parse(JSON.stringify(appPaths)) normalizeCatchAllRoutes(appPaths) expect(appPaths).toMatchObject(initialAppPaths) }) ... ``` ```it('should not add the catch-all route to segments that have a more specific [dynamicRoute]', () => { const appPaths = { '/': ['/page'], '/[[...catchAll]]': ['/[[...catchAll]]/page'], '/nested/[foo]/[bar]/default': [ '/nested/[foo]/[bar]/default', '/nested/[foo]/[bar]/@slot0/default', '/nested/[foo]/[bar]/@slot2/default', ], '/nested/[foo]/[bar]': [ '/nested/[foo]/[bar]/@slot0/page', '/nested/[foo]/[bar]/@slot1/page', ], '/nested/[foo]/[bar]/[baz]': [ '/nested/[foo]/[bar]/@slot0/[baz]/page', '/nested/[foo]/[bar]/@slot1/[baz]/page', ], '/[locale]/nested/[foo]/[bar]/[baz]/[qux]': [ '/[locale]/nested/[foo]/[bar]/@slot1/[baz]/[qux]/page', ], } ... ``` and allow parallel routes defined in this [code repro](https://github.com/williamli/nextjs-NEXT-2165) to build.  ### How? `packages/next/src/build/normalize-catchall-routes.ts` is extended to check `appPath` to see if it is: 1. the route is not a catchall 2. `isMoreSpecific` than the closest `catchAllRoute`. where `isMoreSpecific` is defined as: ``` function isMoreSpecific(pathname: string, catchAllRoute: string): boolean { const pathnameDepth = pathname.split('/').length const catchAllRouteDepth = catchAllRoute.split('/').length - 1 return pathnameDepth > catchAllRouteDepth } ``` --------- Co-authored-by:
Zack Tanner <zacktanner@gmail.com>
-
Shu Ding authored
Currently to redirect to another RSC route of the same app, we initiate another request to that route. This PR changes that request to directly use the internal hostname of the current server handler, rather than relying on other headers. Closes NEXT-2614
-
JJ Kasper authored
-
JJ Kasper authored
-
- 18 Jan, 2024 13 commits
-
-
vercel-release-bot authored
-
Ethan Arrowood authored
Add @Ethan-Arrowood to labeler list
-
vercel-release-bot authored
-
Jiachi Liu authored
`experimental.missingSuspenseWithCSRBailout` should be enabled by default to help users to disciver unwrapped suspense boundaries. Add more notes in the error doc about deprecation and temporary workaround to disable it. Closes NEXT-2157 --------- Co-authored-by:JJ Kasper <jj@jjsweb.site>
-
vercel-release-bot authored
-
Jiachi Liu authored
Follow up for #57953 for DX, give better warnings x-ref: https://github.com/vercel/next.js/pull/60828#discussion_r1457736645 Closes NEXT-2156
-
Jiachi Liu authored
Follow up for #57953 for turbopack side Closes NEXT-2153
-
Steven authored
Revert "Fix: Throw an error for empty array return in `generateStaticParams` with `output:export`" (#60831) Reverts vercel/next.js#57053 per this comment: https://github.com/vercel/next.js/pull/57053#issuecomment-1892747474 Instead of erroring, we should warn (and only in dev mode). That can be added in a future PR. Closes NEXT-2155
-
Jiachi Liu authored
When there’s a request input instance and init object present the same time, we should respect init as preferred Closes NEXT-2149
-
JJ Kasper authored
This ensures we add params for `unstable_cache` so it can be identified the same was as fetches instead of being unlabeled. Closes NEXT-2143
-
JJ Kasper authored
This ensures our in memory cache leveraged for the `fetch-cache` interface is reset per-request instead of using an arbitrary timeout so that we are always pulling the revalidate state from upstream correctly on new requests. Before: https://vercel-revalidate-3zi8wpexo-vtest314-ijjk-testing.vercel.app/ After: https://vercel-revalidate-70y5a8dbh-vtest314-ijjk-testing.vercel.app/ Closes: https://github.com/vercel/next.js/issues/60680 Closes NEXT-2144
-
Lee Robinson authored
-
Leah authored
### What? We were missing the alias (and config field) for custom image loaders. Closes PACK-2190 Fixes #60097
-