Commit graph

22 commits

Author SHA1 Message Date
Steven
4b4925f4e8
fix: set cookies followed by redirect() (#49965)
- Fixes #49237 


fix NEXT-1120

Co-authored-by: Wyatt Johnson <633002+wyattjoh@users.noreply.github.com>
2023-05-19 00:17:19 +00:00
Tim Neutkens
25a9547cad
Remove experimental config from create-next-app (#49241)
## What?

Removes `experimental.appDir` this was leftover from when I flipped the
switch.

Kept the config file as in the future we might add future flags and
such. It also helps that it has the types comment included so you always
get types.

<!-- 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 or adding/fixing 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 #

-->

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-05-05 00:22:28 -07:00
JJ Kasper
7bfd582999
Ensure WebSocket is polyfilled for node runtime as well (#48924)
Follow-up to https://github.com/vercel/next.js/pull/48870 this exposes
WebSocket for the Next.js runtime so we don't have divergence in APIs as
discussed with @cramforce
2023-04-28 15:48:14 -05:00
Wyatt Johnson
045ad0d133
Replaced Reflect with ReflectAdapter (#48000)
On some runtimes, `Reflect` is not available. This creates a new "naive"
implementation.
2023-04-06 21:18:42 +02:00
Tim Neutkens
d32ee25bfb
Add dynamic parameter marker to router cache key (#47957)
### What?

Took a bit to investigate this one, eventually found that the case where
it broke is this one:

```
app
├── [slug] // This matches `/blog`
│   └── page.js
└── blog
    └── [name] // This matches `/blog/a-post`
        └── page.js
```

The router cache key is based on the "static key" / "dynamic parameter
value" in the tree. This means that the cache key for `/blog` that
matches `/[slug]` would be the same as the static segment `blog`. This
caused the cache to become intertwined between those paths, it's
accidental that the router got stuck in that case, main reason it got
stuck is that the fetch for the RSC payload returned a deeper value than
expected. In `walkAddRefetch` we bailed because that walked the
`segmentPath` didn't match up.

The underlying problem with this was that the render would override the
cache nodes incorrectly. This would also cause wrong behavior, even
though that wasn't reported. E.g. `app/[slug]/layout.js` would apply on
`app/blog/[name]/page.js` because they'd share the `blog` cache node.

### How?

This PR changes the cache key to include the dynamic parameter name and
type, e.g. the dynamic segment `['slug', 'blog', 'd']` previously turned
into `'blog'` as the cache key, with these changes it turns into
`'slug|blog|d'`. For static segments like `blog` in `app/blog/[name]`
the key is still just `'blog'`.

I've also refactored the cases where we read the segment as the code was
duplicated in a few places.


Closes NEXT-877
Fixes #47297

<!-- 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 or adding/fixing 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 #

-->

fix NEXT-877
2023-04-05 15:40:28 +02:00
Wyatt Johnson
aca83d2a09
Move App Route handler logic into bundle (#47633)
Previously the app route handler was included in the server bundle, and called into user code to execute the underlying handler logic. This PR serves to move the handler code into the bundle so that the Node.js environment more closely matches the Edge environment.

This also updates the Rust code for the new loader.
fix NEXT-712 ([link](https://linear.app/vercel/issue/NEXT-712))
2023-03-29 19:31:30 +00:00
JJ Kasper
4d0f5a0503
Revert "Move App Route handler logic into bundle" (#47614)
Reverts vercel/next.js#47582

This breaks turbopack support so we should address that before landing.
Potentially we can re-use the same loader for both which would eliminate
this issue.

x-ref:
https://github.com/vercel/next.js/actions/runs/4544370605/jobs/8010399819
x-ref:
https://github.com/vercel/next.js/actions/runs/4545240650/jobs/8012475072?pr=47611
fix NEXT-712 ([link](https://linear.app/vercel/issue/NEXT-712))
2023-03-28 10:12:03 -07:00
Wyatt Johnson
5dc31354b9
Move App Route handler logic into bundle (#47582)
Previously the app route handler was included in the server bundle, and
called into user code to execute the underlying handler logic. This PR
serves to move the handler code into the bundle so that the Node.js
environment more closely matches the Edge environment.
fix NEXT-712 ([link](https://linear.app/vercel/issue/NEXT-712))
2023-03-28 16:38:17 +02:00
Ngô Đức Anh
c748b16555
Feat(next-types-plugin): added support for Route Handlers (#47185)
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 or adding/fixing 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?

This PR adds next-types-plugin's support for Route Handlers.

### Why?

Since `route.js` is somewhat like `page.js` and `layout.js`, I find it to be necessary that we also enable TS checks for these files as well.

### How?

Just changing the `createTypeGuardFile` function a bit and adding a few new tests, yeah.
2023-03-26 23:34:54 +00:00
Jiachi Liu
93152db9b1
Fix bad route path for custom metadata routes (#47286)
We introduced static route `robots.txt` and dynamic route `robots.js` for metadata, it should still allow users to create their own customized version. This issue is caused by a route conflicts. Only append `/route` to page path when there's not ending with `/route`


Fixes #47198
Closes NEXT-850
2023-03-21 15:55:32 +00:00
Wyatt Johnson
0be4db325e
Warn about default exports with App Routes (#47263)
When a user exports a default function from a `route.ts` file, they may
think that this would be handled in the same way that our `pages/api/`
routes handled it. App Routes require an exported function for each HTTP
method instead.

This adds warnings to the development console when a user provides a
default export (or no HTTP method at all).

Future ideas:

- Error during production build when these conditions are met
fix #46375
fix NEXT-660 ([link](https://linear.app/vercel/issue/NEXT-660))

---------

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-03-20 14:52:41 -07:00
JJ Kasper
76f7645ce6
Update app route handler proxy handling (#47088)
This ensures our Proxy wrapping request fields works properly in the
edge-runtime by explicitly binding to the correct request instance.

x-ref: [slack
thread](https://vercel.slack.com/archives/C03UR7US95F/p1678730563467089?thread_ts=1678662292.695769&cid=C03UR7US95F)
2023-03-13 11:34:22 -07:00
Wyatt Johnson
45492eacc0
Fix originalRequest not available for edge requests (#46741)
For requests made via the edge runtime, they will not contain the
`originalRequest` object used by the request storage to enable
headers/cookie access. This uses the request object passed when in the
edge runtime.
2023-03-03 18:14:49 +00:00
Wyatt Johnson
3229ed79a6
Support force-static on App Routes (#46693)
Supports `export const dynamic = 'force-static'` on App Routes. This strips pieces of information from the request object to ensure subsequent requests don't accidentally cache user specific data:

- Removes `searchParams`
- Removes `headers`
- Removes `cookies`
- Removes `host`
- Removes `port`
- Removes `protocol`

[NEXT-682](https://linear.app/vercel/issue/NEXT-682/force-static-doesnt-work-with-app-routes)
2023-03-02 19:28:37 +00:00
JJ Kasper
99a7a34f96
Ensure generateStaticParams works in route (#46310)
x-ref: [slack
thread](https://vercel.slack.com/archives/C04DUD7EB1B/p1677165000745519)

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

---------

Co-authored-by: Jimmy Lai <laijimmy0@gmail.com>
2023-02-23 18:33:08 +01:00
JJ Kasper
1253a3035f
Add ISR handling for app routes (#46133)
Follow-up to https://github.com/vercel/next.js/pull/45716 this updates
the ISR handling for app routes. This also ensures the E2E deploy tests
are running for the `app-routes` test suite.

fixes NEXT-509

Relies on https://github.com/vercel/vercel/pull/9489

---------
2023-02-21 15:25:42 -08:00
Tim Neutkens
5599c47ed6
Add edge support for route handlers (#45990)
- Add test for edge route
- Add edge route loader
- Ensure edge route does not trigger static generation
- Remove unused import
- Use new loader during compilation
- Add names for routeKind to help debugging
- Ensure route is considered a appDir page
- Return response from edge runtime
- Handle edge route in dev and prod

Fixes NEXT-510

<!--
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:
-->

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see
[`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-16 16:32:37 +01:00
JJ Kasper
3e919b6add
Fix flakey app cli output checks (#45960)
x-ref:
https://github.com/vercel/next.js/actions/runs/4186567737/jobs/7255320047
2023-02-15 11:33:17 -08:00
Hannes Bornö
087aa6e83e
Log dev error in Server Router (#45951)
Fixes NEXT-561

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see [`contributing.md`](https://github.com/vercel/next.js/blob/canary/contributing.md)

## Feature

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

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm build && pnpm lint`
- [ ] The "examples guidelines" are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)
2023-02-15 17:09:48 +00:00
JJ Kasper
778a2a7442
Fix app routes on deploy (#45931)
Follow-up to https://github.com/vercel/next.js/pull/45716 this ensures
we correctly construct the initial URL value as it must be a fully
qualified URL. Existing tests caught this failure when running in deploy
mode.
2023-02-15 09:54:39 +01:00
JJ Kasper
7d8f85bd8d
Update E2E deploy tests (#45929)
Updates test cases that aren't expected to work for deploy mode at the
moment.

x-ref:
https://github.com/vercel/next.js/actions/runs/4180235531/jobs/7241206278
2023-02-14 20:00:58 -08:00
Wyatt Johnson
74ca99c866
Server Router Improvements (#45716)
This adds updated matching handle for the server to separate out the matching and executing of different route types e.g. page routes, API routes, and app routes. 

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2023-02-15 00:16:45 +00:00