- 04 Mar, 2024 7 commits
-
-
JJ Kasper authored
-
Jiachi Liu authored
Fixes the string id that broken when sitemap is optimized to static route. When sitemap is optimized to static route in production, the route argument is changed from `[[...__metadata_id__]]` to `[__metadata_id__]`, so the type of it is also changed from array to string that should reflect in the loader code. Fixes #60894 Closes NEXT-2154
-
Abhinay Pandey authored
generateSitemaps function returns a 404 for /sitemap/[id].xml in production While finding the correct sitemap partition from the array, we check the param against the id. Which works in dev because id and param are both without trailing .xml. But it fails in production as param has a trailing .xml (/sitemap/[id] works in production because it falls back to dynamic loading and param and id are both without .xml) If we are in production environment, check the id with a trailing .xml because that's whats returned from generateStaticParams, an array of __metadata_id__ with trailing .xml Fixes #61969 --------- Co-authored-by:Jiachi Liu <inbox@huozhi.im>
-
Jiachi Liu authored
Fixes `redirect()` call under suspense boundary, redirect url should include the `basePath` in the url. `redirect()` under suspense boundaries will go through server html insertion, which is being used every time by suspense boundary resolved, new errors will triggered from SSR streaming. It was missing before. Fixes NEXT-2615 Fixes #62407
-
Shu Ding authored
As mentioned in the new-added error messages, and the [linked resources](https://react.dev/reference/react/use-server#:~:text=Because%20the%20underlying%20network%20calls%20are%20always%20asynchronous%2C%20%27use%20server%27%20can%20only%20be%20used%20on%20async%20functions.): > Because the underlying network calls are always asynchronous, 'use server' can only be used on async functions. > https://react.dev/reference/react/use-server It's a requirement that only async functions are allowed to be exported and annotated with `'use server'`. Currently, we already have compiler check so this will already error: ```js 'use server' export function foo () {} // missing async ``` However, since exported values can be very dynamic the compiler can't catch all mistakes like that. We also have a runtime check for all exports in a `'use server'` function, but it only covers `typeof value === 'function'`. This PR adds a stricter check for "use server" annotated values to also make sure they're async functions (`value.constructor.name === 'AsyncFunction'`). That said, there are still cases like synchronously returning a promise to make a function "async", but it's still very different by definition. For example: ```js const f = async () => { throw 1; return 1 } const g = () => { throw 1; return Promise.resolve(1) } ``` Where `g()` can be synchronously caught (`try { g() } catch {}`) but `f()` can't even if they have the same types. If we allow `g` to be a Server Action, this behavior is no longer always true but depending on where it's called (server or client). Closes #62727.
-
Zack Tanner authored
### What When attaching a rejection listener to a server action promise, in the case of network errors, the rejection handler would be skipped and it'd throw an error that crashes the application. ### Why When we refactored these reducers to no longer suspend, it caused the rejection handling logic we have to no longer make sense. In this case we're working with a native promise that won't have a `status` property, so we'd re-throw the error and not call `reject`. ### How This removes the special status handling logic and makes the rejection handler always call `reject` with the error. This will either be handled by user code or let the error bubble to an error boundary. I also cleaned up some mutable code that is no longer needed now that these reducers aren't replayed. Closes NEXT-1715 Closes NEXT-2323 Fixes #58638
-
Zack Tanner authored
Following an anchor link to a hash param, and then attempting to use `history.pushState` or `history.replaceState`, would result in an MPA navigation to the targeted URL. In #61822, a guard was added to prevent calling `ACTION_RESTORE` with a missing tree, to match other call-sites where we do the same. This was to prevent the app from crashing in the case where app router internals weren't available in the history state. The original assumption was that this is a rare / unlikely edge case. However the above scenario is a very probable case where this can happen, and triggering an MPA navigation isn't ideal. This updates `ACTION_RESTORE` to be resilient to an undefined router state tree. When this happens, we'll still trigger the restore action to sync params, but use the existing flight router state. Closes NEXT-2502
-
- 02 Mar, 2024 3 commits
- 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 3 commits
-
-
vercel-release-bot authored
-
Ethan Arrowood authored
Add @Ethan-Arrowood to labeler list
-
vercel-release-bot authored
-