Skip to content
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

[pull] canary from vercel:canary #2040

Open
wants to merge 6,885 commits into
base: canary
Choose a base branch
from
Open

[pull] canary from vercel:canary #2040

wants to merge 6,885 commits into from

Conversation

pull[bot]
Copy link

@pull pull bot commented Mar 27, 2024

See Commits and Changes for more details.


Created by pull[bot]

Can you help keep this open source service alive? 💖 Please sponsor : )

devjiwonchoi and others added 26 commits January 24, 2025 20:06
Allows us to remove some `any` casts and `@ts-expect-error`.
#75052)

### What?

Chunk async loaders together with normal chunk items to avoid multiple chunkings and small chunks
### What?

It **removes** needless allocations.

### Why?

To avoid allocating memory needlessly.
### What?

Reduce allocations for SWC plugins, by applying
swc-project/plugins#393

### Why?

Those are actually noop so they should not allocate too much.
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
)

The issues with the current export statement validation for app router
pages are documented in the added fixtures, see also the inline comments
in the diff.
Fixes all issues related to the current export statement validation for
app router pages, as highlighted in #75277.
…75279)

The `"use cache"` directive is not compatible with the Edge runtime.

When the `experimental.useCache` flag is enabled, we now emit a build
error for pages with `export const runtime = 'edge'`. This is analogous
to using the `experimental.dynamicIO` flag.

The other route segment configs that are forbidden when `dynamicIO` is
enabled, are currently still allowed for `useCache`:

- `dynamicParams`
- `dynamic`
- `fetchCache`
- `revalidate`
### What?

* change turbopack-cli to new backend
* avoid transient tasks in turbopack-cli
### What?

NextJS should not throw `The "use server" file can only export async
functions.` for type exports.

### Why?

Because type exports are just a compile time abstraction.
…low local-task-based argument resolution (#75214)

Removes the (now default) feature flag for local task argument resolution.

With local-task based argument resolution in place, we don't need to support argument resolution in the backend, which simplifies some code.
…is_call/native_this_call (#75253)

The `_this` argument variants of these functions are 99% of the same, so this deduplicates them.
…outputs and cells (#75171)

We only read data owned by the the currently-executing task when reading from a local Vc, so:
- A separate "untracked" API doesn't make sense. There's never any tracking needed for reading local outputs or cells. (would we mark the current task as dependent on itself?)
- Allowing a `consistency` argument isn't useful because you can't strongly consistently await your own task.
- We don't need to call `notify_scheduled_tasks`, we're not adding any new task dependencies.
A function returning an `OperationVc` can call a transient function or have a transient argument.

IMO, `TaskInput` should not have default method implementations to avoid potential footguns like this.
### What?

This reduces the overallocated memory by InnerStorage instances in the DashMap capacity
### What?

* move code from macro into generic struct
* move dynamic storage access into separate struct
* generate inline storage for common data
This improves the build script quite a bit and makes dev editing much
faster. Also fixed excludes causing webpack/babel compiled packages to
be bundled into the runtime un-necessarily reducing from `10MB` ->
`1.2MB`.

Before: `Finished next_bundle in 9.67s`

After: `Finished next_bundle in 1.27s`

Validated here
https://github.com/vercel/vercel/actions/runs/12957911052/job/36147343396?pr=12914
….)]` (#75259)

Allows tasks to be marked as local using `#[turbo_tasks::function(local)]`.

Local tasks are cached only for the lifetime of the nearest non-Local parent caller.

Local tasks do not have a unique task id, and are not shared with the backend. Instead they use the parent task's id and store data in the backend-agnostic manager.

This is useful for functions that have a low cache hit rate. Those functions could be converted to non-task functions, but that would break their function signature. This provides a mechanism for skipping caching without changing the function signature.

Local tasks are already used for argument resolution, this allows other arbitrary functions to be opted-in.
### What?

* more memory efficient AggregationUpdateQueue by using SmallVec and
boxing some job types
* avoid allocation in CaptureFuture by avoiding the Arc and the Mutex
and using a thread local reference
Just ensures we keep mangling behavior prior to
#75294

---------

Co-authored-by: Hendrik Liebau <mail@hendrik-liebau.de>
mischnic and others added 30 commits February 6, 2025 17:19
Way less turbo tasks

Less CPU time, 300mb less memory.

```
testing against 0293c96cf32

uncell AstPath 77d7015 (PR below in this stack)
13,65 GB 
TURBO_ENGINE_READ_ONLY=1 NEXT_TURBOPACK_TRACING= TURBOPACK=1 TURBOPACK_BUILD=  505.04s user 83.92s system 853% cpu 1:09.00 total
TURBO_ENGINE_READ_ONLY=1 NEXT_TURBOPACK_TRACING= TURBOPACK=1 TURBOPACK_BUILD=  509.03s user 84.26s system 829% cpu 1:11.53 total

snapshot in with_modules c2c661b
13,3 GB
TURBO_ENGINE_READ_ONLY=1 NEXT_TURBOPACK_TRACING= TURBOPACK=1 TURBOPACK_BUILD=  491.50s user 79.78s system 856% cpu 1:06.69 total
TURBO_ENGINE_READ_ONLY=1 NEXT_TURBOPACK_TRACING= TURBOPACK=1 TURBOPACK_BUILD=  495.62s user 78.61s system 852% cpu 1:07.36 total
```
Lifts the style fix from #75718 into a separate PR.

Fixes the feedback bar clipping the content:

![410278234-8a7d9d9e-b483-4019-bc8a-524e755b3dd7](https://github.com/user-attachments/assets/3dd90148-6835-4954-9341-ae10c3c14679)

Co-authored-by: Jude Gao <jude.gao@vercel.com>
…riginal stack frames (#75743)

### Why?

When fetch fails to get the original stack frames, the process to get the Runtime Errors fails.
The fetch will likely fail on Storybook stories.

| Before | After |
|--------|--------|
| ![CleanShot 2025-02-06 at 21 21 19](https://github.com/user-attachments/assets/7e136a02-8b1f-4ec0-8430-e02d919610c3) | ![CleanShot 2025-02-06 at 21 21 33](https://github.com/user-attachments/assets/5ce9f95f-f5a2-4738-b8c5-5152733aeab7) | 

### How?

Correctly reject when request fails so that it may be caught at `_getOriginalStackFrame()` and return the stack frame.
Add and apply the merge multiple class names util.

Closes NDX-664

---------

Co-authored-by: Jiachi Liu <inbox@huozhi.im>
No significant perf impact
This was dead code after we removed `swc_css`
)

## Why?

To track issues that are marked "not stale," we need to explicitly add a not stale label. https://github.com/actions/stale does not use this label by default.
## What?
This addresses [#68217](#68217)
where middleware, incorrectly, does not run for _next/image requests.

We can confirm this is not correct behavior through the explanation of
middleware matchers in
[docs](https://nextjs.org/docs/app/building-your-application/routing/middleware#matcher)
> The matcher config allows full regex so matching like negative
lookaheads or character matching is supported. An example of a negative
lookahead to match all except specific paths can be seen here:
> ```typescript
> export const config = {
>   matcher: [
>     /*
>      * Match all request paths except for the ones starting with:
>      * - api (API routes)
>      * - _next/static (static files)
> * - _next/image (image optimization files) <- This means middleware
**should** run for _next/image
>      * - favicon.ico, sitemap.xml, robots.txt (metadata files)
>      */
>
'/((?!api|_next/static|_next/image|favicon.ico|sitemap.xml|robots.txt).*)',
>   ],
> }
> ```



### When did this regress
The regression happened here
https://github.com/vercel/next.js/pull/57161/files#diff-6f4291cc2bfc5073fdca12a014011769e840ee68583db1468acef075f037015aL1245

> The diff since github isn't inlining the diff
> ```diff
> - let finished = await this.handleNextDataRequest(req, res, parsedUrl)
> + finished = await this.handle(req, res, parsedUrl)
> ```

> Note, `handle` groups calls to `handleNextDataRequest` **and**
`handleImageRequest`

https://github.com/vercel/next.js/pull/57161/files#diff-6f4291cc2bfc5073fdca12a014011769e840ee68583db1468acef075f037015aR1316-R1328

### Why was this a regression
Inside of `handle`, there is a new call to `handleNextImageRequest`
(this fn handles image optimization).

This ends up causing image optimization to run before user middleware
code runs. When the image optimization completes, the server behaves as
if the entire middleware pipeline is complete, which is **before** user
middleware code is ran


https://github.com/vercel/next.js/blob/d2711d22fb719131d63cbce05a6306917f3626ea/packages/next/src/server/base-server.ts#L1528-L1540

Said plainly, image optimization now runs in middleware. And when image
optimization completes, it blocks user middleware code from running.

Im going to assume this was an incorrect refactor since there did not
seem to be a motivation for the behavior change in
#57375

### Solution
The solution proposed is to follow the same behavior as
`handleNextDataRequest`, which early returns during middleware:


https://github.com/vercel/next.js/blob/d2711d22fb719131d63cbce05a6306917f3626ea/packages/next/src/server/base-server.ts#L728-L745


> Note, `handleNextDataRequest` has an extra condition that it only
skips middleware requests when its not on edge. I’m going to assume this
is not what we want for image optimization, since there was never an
edge check for image optimization- to hedge I don’t have any knowledge
on what can run on edge in this context


And for confirmation that the new ```handleNextImageRequest``` (added in
the regression mentioned) is truly redundant, you can confirm the image
optimization happens when `invokePath` is specified in the request meta
or when `'x-matched-path'` header exists (as far as my understanding
goes, and based on the behavior I observed from runtime checks, these 2
cases should be exhaustive) :


https://github.com/vercel/next.js/blob/d2711d22fb719131d63cbce05a6306917f3626ea/packages/next/src/server/base-server.ts#L1470-L1526


https://github.com/vercel/next.js/blob/d2711d22fb719131d63cbce05a6306917f3626ea/packages/next/src/server/base-server.ts#L1078-L1378

> what's relevant in both above snippets
> ```typescript
> finished = await this.normalizeAndAttachMetadata(req, res, parsedUrl)
>    if (finished) return 
> ```


> Note: it's probably optimal to not call normalizeAndAttachMetadata in
the if middleware branch at all since both handlers in the function now
no-op if they are handling middleware (which is guaranteed in that
branch). Im not applying that change here to avoid scope of the fix, but
can make the refactor upon request


https://github.com/vercel/next.js/blob/d2711d22fb719131d63cbce05a6306917f3626ea/packages/next/src/server/base-server.ts#L1633-L1646


## TLDR
The problem is that image optimization runs before user middleware code,
and when it completes successfully, it skips running user middleware
code- which means requests to _next/image will not have middleware run
for them. The solution is to not run the image optimization in
middleware that caused the skip

Fixes #68217

---------

Co-authored-by: Joseph Chamochumbi <jchamoch@volvocars.com>
Errors thrown by the lint worker would only surface the error if
`JEST_WORKER_ID` is present. This check was not reliably truthy in all
cases (eg, when run with the vercel CLI, `JEST_WORKER_ID` wasn't
present) which meant the build would fail with no helpful error message.
Outside of that, it was a brittle check because if jest-worker ever
changed or removed this env, or we replaced the underlying worker
library, this would start failing.

This updates the check to be a more explicit env variable that we
control.

Fixes NEXT-3994
This makes sure we properly copy the necessary files in standalone mode
and node middleware is configured also adds regression test for this.
…t's like getServerSideProps (#75773)

## Why?

`force-dynamic` is not like `getServerSideProps` in Pages Router, so this bullet point needs to be removed.

- Fixes #75697
Co-authored-by: Sebastian Sebbie Silbermann <sebastian.silbermann@vercel.com>
<!-- Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change(s) that you're making:

## For Contributors

### Improving Documentation

- Run `pnpm prettier-fix` to fix formatting issues before opening the
PR.
- Read the Docs Contribution Guide to ensure your contribution follows
the docs guidelines:
https://nextjs.org/docs/community/contribution-guide

### Adding or Updating Examples

- The "examples guidelines" are followed from our contributing doc
https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md
- Make sure the linting passes by running `pnpm build && pnpm lint`. See
https://github.com/vercel/next.js/blob/canary/contributing/repository/linting.md

### Fixing a bug

- Related issues linked using `fixes #number`
- Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md

### Adding a feature

- Implements an existing feature request or RFC. Make sure the feature
request has been accepted for implementation before opening a PR. (A
discussion must be opened, see
https://github.com/vercel/next.js/discussions/new?category=ideas)
- Related issues/discussions are linked using `fixes #number`
- e2e tests added
(https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs)
- Documentation added
- Telemetry added. In case of a feature if it's used or not.
- Errors have a helpful link attached, see
https://github.com/vercel/next.js/blob/canary/contributing.md


## For Maintainers

- Minimal description (aim for explaining to someone not on the team to
understand the PR)
- When linking to a Slack thread, you might want to share details of the
conclusion
- Link both the Linear (Fixes NEXT-xxx) and the GitHub issues
- Add review comments if necessary to explain to the reviewer the logic
behind a change

### What?

### Why?

### How?

Closes NEXT-
Fixes #

-->
### What?

Update swc_core, and enable `swc_core/ecma_ast_shrink`.

ChangeLog: swc-project/swc@swc_core@v13.0.4...swc_core@v13.1.0


### Why?

 - To add `AST.shrink_to_fit()`.
 - To apply memory usage optimizations.
…#75802)

## Why?

Issues with the `Documentation` **Type**, which is issues opened via the `Documentation` issue template, should not be prematurely closed with **Invalid Link** from [nissuer](https://github.com/balazsorban44/nissuer).
### What?

Use `shrink-to-fit` crate instead of inline trait in turbo-tasks.

### Why?

It's a separate crate, so SWC AST implement the `ShrinkToFit` trait.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.