Commit graph

39 commits

Author SHA1 Message Date
Chris Frank
44aeb083cc
Fix internal route redirection with absolute urls outside basePath (#64604)
When performing a redirect() with an absolute path, action-handler
attempts to detect whether the resource is hosted by NextJS. If we
believe it is, we then attempt to stream it.

Previously we were not accounting for basePath which caused absolute
redirects to resources on the same host, but not underneath the
basePath, to be resolved by NextJS. Since the resource is outside the
basePath we resolve a 404 page which returns back as `text/x-component`
and is thus streamed back to the client within the original POST
request.

This PR adds a check for the presence of the basePath within absolute
redirect URLs. This fixes the above problem.

fixes #64413
fixes #64557

---------

Signed-off-by: Chris Frank <chris@cfrank.org>
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-06-18 06:58:38 -07:00
Hendrik Liebau
994d8ee2c3
Fix broken BrowserInterface type (#66461) 2024-06-03 12:56:49 +00:00
Hendrik Liebau
71c21dfc9a
Set default playwright timeout to NEXT_E2E_TEST_TIMEOUT (#66258)
This allows us to set breakpoints and debug e2e tests without
encountering a timeout after 60 seconds. For example, using:
    
```
NEXT_E2E_TEST_TIMEOUT=1000000 NODE_OPTIONS=--inspect-brk pnpm test-dev test/e2e/app-dir/metadata/metadata.test.ts
```
    
Notably, this change also affects the turbopack dev tests in the CI,
where `NEXT_E2E_TEST_TIMEOUT` is currently set to 240 seconds. Since the
same env variable is also used for `jest.setTimeout()`, a test timeout
will now most likely occur due to jest timing out, and not a specific
playwright check (i.e. `waitForElementByCss` or `waitForCondition`)
timing out. This sounds acceptable to me.

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2024-05-29 03:21:42 +00:00
Leah
60f0837b67
refactor(tests): make chain more "correct" (#51728)
### Why?

I really dislike the way `.chain` works right now, it shouldn't mutate
the `BrowserInterface`, this PR changes it so it's just a pure chain
without weird side effects.

One example with the current version (before this PR):
```
const el = browser.elementByCss('#version-2')
await el.text()
// throws
await el.text()
```

### Additional Changes

- removes selenium (which is completely unused)
- updates playwright
- makes the playwright tracing not error all the time
2024-02-14 20:14:24 +01:00
Wyatt Johnson
dda1870501
Reapply "feat(app-router): introduce experimental.missingSuspenseWithCSRBailout flag" (#60508) (#60751)
This reapplies the `experimental.missingSuspenseWithCSRBailout` option
to bail out during build if there was a missing suspense boundary when
using something that bails out to client side rendering (like
`useSearchParams()`). See #57642

Closes [NEXT-1770](https://linear.app/vercel/issue/NEXT-1770)
2024-01-17 12:33:45 +01:00
OJ Kwon
61889f8969
fix(playwright): teardown when global quit force terminates browser (#59548) 2023-12-12 15:18:47 -08:00
OJ Kwon
2dbd4e7529
test(fixture): try to include sources in the snapshot (#59499) 2023-12-11 18:10:34 -08:00
OJ Kwon
25d58d4c5a
test(runner): preserve browser tracing if test fails (#59469) 2023-12-11 08:21:46 -08:00
Zack Tanner
a578cc8192
fix inconsistent scroll restoration behavior (#59366)
### What?
While scrolled on a page, and when following a link to a new page and
clicking the browser back button or using `router.back()`, the scroll
position would sometimes restore scroll to the incorrect spot (in the
case of the test added in this PR, it'd scroll you back to the top of
the list)

### Why?
The refactor in #56497 changed the way router actions are processed:
specifically, all actions were assumed to be async, even if they could
be handled synchronously. For most actions this is fine, as most are
currently async. However, `ACTION_RESTORE` (triggered when the
`popstate` event occurs) isn't async, and introducing a small amount of
delay in the handling of this action can cause the browser to not
properly restore the scroll position

### How?
This special-cases `ACTION_RESTORE` to synchronously process the action
and call `setState` when it's received, rather than creating a promise.
To consistently reproduce this behavior, I added an option to our
browser interface that'll allow us to programmatically trigger a CPU
slowdown.

h/t to @alvarlagerlof for isolating the offending commit and sharing a
minimal reproduction.

Closes NEXT-1819
Likely addresses #58899 but the reproduction was too complex to verify.
2023-12-07 11:17:15 -08:00
Zack Tanner
df12508be2
use experimentalHttpsServer flag when determining image optimizer protocol (#55988)
Inferring the protocol from the request meta is not reliable when the next server is running over `http` but sitting behind an https proxy. This instead plumbs the experimental https flag through to the optimizer so we can more reliably determine the protocol

Fixes #55971
2023-09-26 05:35:06 +00:00
Tim Neutkens
f313235428
Remove pong HMR event as it is not used (#54965)
While investigating the HMR event types I noticed `pong` is not being used in Pages Router nor in App Router.

This PR removes the code that sends it as it's essentially dead code.
2023-09-04 13:27:47 +00:00
Zack Tanner
c676f9357e
fix bfcache restoration behavior (#54198)
Follow up to https://github.com/vercel/next.js/pull/54081 -- this was
restoring the router tree improperly causing an error on bfcache hits

Had to override some default behaviors to prevent `forward` / `back` in
playwright from hanging indefinitely since no load event is firing in
these cases

Fixes #54184
Closes NEXT-1528
2023-08-18 00:05:26 +02:00
Zack Tanner
0b3e366f32
fix routing bug when bfcache is hit following an mpa navigation (#54081)
When an mpa navigation takes place, we currently push the user to the new route and suspend the page indefinitely (x-ref: #49058). When navigating back, if the browser opts into using the [bfcache](https://web.dev/bfcache/), it will remain suspended and `pushRef.mpaNavigation` will be true. This means that anything that would cause the component to re-render will trigger the mpa navigation again (such as hovering over another `Link`, as reported in #53347)

This PR checks to see if bfcache is being used by observing `PageTransitionEvent.persisted` and if so, resets the router state to clear out `pushRef`. 

Closes NEXT-1511
Fixes #53347
2023-08-16 17:55:06 +00:00
Dima Voytenko
4c14482553
[chore] Upgrade playwright to 1.35.1 (#53875) 2023-08-11 23:25:01 +00:00
Leah
5d54eaaf18
type check tests (and convert next-test-utils.js to ts) (#51071)
Enables type checking for tests in CI and fixes a bunch of things related to that
2023-06-23 17:42:50 +00:00
Sebastian Markbåge
b877de1442
Enable progressive enhanced form actions through decodeAction (#49187)
This uses the new built-in progressive enhancement features of React.
These always use `multipart/form-data` atm. When one comes in that's not
a fetch, we can use `decodeAction` to get a resolved function.

This also ensures that we can test this by passing disableJavaScript to
tests. This disables JS for the context.
2023-05-04 05:03:09 +00:00
Jiachi Liu
7de1a4070d
Reland "app-router: new client-side cache semantics" (#48695)
Reverts vercel/next.js#48688
fix NEXT-1011
2023-04-22 10:41:08 +00:00
Jiachi Liu
8089d0a3bb
Revert "Reland app-router: new client-side cache semantics" (#48688)
Reverts vercel/next.js#48685

Temporary Revert again to investigate the hang job
fix NEXT-1011
2023-04-21 22:36:28 +02:00
Jiachi Liu
b61305afcc
Reland app-router: new client-side cache semantics (#48685)
Reland vercel/next.js#48383
fix NEXT-1011
2023-04-21 19:39:06 +00:00
Jiachi Liu
52fcc59717
Revert "app-router: new client-side cache semantics" (#48678)
Reverts vercel/next.js#48383
fix NEXT-1011

revert and re-land later
2023-04-21 17:21:58 +00:00
Jimmy Lai
658c600534
app-router: new client-side cache semantics (#48383)
This PR implements new cache semantics for the app router on the client.

## Context

Currently, on the App Router, every Link navigation is prefetched and
kept forever in the cache. This means that once you visit it, you will
always see the same version of the page for the duration of your
navigation.

## This PR

This PR introduces new semantics for how the App Router will cache
during navigations. Here's a TL;DR of the changes:
- all navigations (prefetched/unprefetched) are cached for a maximum of
30s from the time it was last accessed or created (in this order).
- in addition to this, the App Router will cache differently depending
on the `prefetch` prop passed to a `<Link>` component:
  - `prefetch={undefined}`/default behaviour:
- the router will prefetch the full page for static pages/partially for
dynamic pages
    - if accessed within 30s, it will use the cache
- after that, if accessed within 5 mins, it will re-fetch and suspend
below the nearest loading.js
- after those 5 mins, it will re-fetch the full content (with a new
loading.js boundary)
  - `prefetch={false}`:
    - the router will not prefetch anything
    - if accessed within 30s again, it will re-use the page
    - after that, it will re-fetch fully
  - `prefetch={true}`
- this will prefetch the full content of your page, dynamic or static
    - if accessed within 5 mins, it will re-use the page

## Follow ups

- we may add another API to control the cache TTL at the page level
- a way to opt-in for prefetch on hover even with prefetch={false}


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

-->

link NEXT-1011
2023-04-21 14:29:39 +02:00
JJ Kasper
320ebe2d34
Update flakey tests and add Node.js setup retrying (#47871)
x-ref:
https://github.com/vercel/next.js/actions/runs/4599615812/jobs/8125278036
x-ref:
https://github.com/vercel/next.js/actions/runs/4598323624/jobs/8124618075?pr=47365
x-ref:
https://github.com/vercel/next.js/actions/runs/4598323624/jobs/8124612692?pr=47365
2023-04-03 13:37:14 -07:00
Shu Uesugi
723626cf48
Handle defaultLocale on client router filter (#47180)
x-ref: [slack
thread](https://vercel.slack.com/archives/C03S8ED1DKM/p1678838567947919)

Follow-up to https://github.com/vercel/next.js/pull/46317. The issue is
that, if:

- `experimental.clientRouterFilter` is enabled
- `i18n` is enabled with `defaultLocale` set
- Next.js router navigates to a path that (1) is the same as
`defaultLocale` and (2) will be redirected,

then:

- **Expected:** Should hard-navigate to this path without any locale
prefix (and then redirect occurs)
- **Actual:** Hard-navigates to this path with `defaultLocale` prefix,
even though it's not needed (and then redirect occurrs)

### Solution

This PR fixes the above issue by adding `defaultLocale` to `addLocale`
which is passed to `handleHardNavigation`. [`addLocale` skips adding the
locale if `locale` is equal to
`defaultLocale`](02125cf3b1/packages/next/src/shared/lib/router/utils/add-locale.ts (L17)).

### Fixing a bug

- [x] Related issues linked using `fixes #number`
- [x] Tests added. See:
https://github.com/vercel/next.js/blob/canary/contributing/core/testing.md#writing-tests-for-nextjs

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2023-03-16 11:58:02 -07:00
Jan Kaifer
b386f680cc
Update handling of autoscrolling on navigation in app (#43845)
- Add support for scrolling to the sides and down when navigating
- Add tests for vertical scrolling
- Add tests for horizontal scrolling
- Add tests for `router.refresh()`
	- should not scroll by itself
	- should not block router.push from scrolling
	- should not scroll when page refreshed using fash refresh
- Scroll to the top of document if that gets page into viewport
	- I didn't want to implement some heuristics on if we can scroll to the top of the page so I just scroll there and check.
	- This implementation may not play well with some nested scrollable containers (but that never worked, just FYI)
	
- Improved typings on `BrowserInterface` a little - backward compatible change.

Co-authored-by: Shu Ding <3676859+shuding@users.noreply.github.com>
2023-01-24 15:41:06 +00:00
Jan Kaifer
66408466ad
Document how chain works in BrowserInterface and chain to browser.eval (#44085)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-12-20 13:03:51 +01:00
Jaril
06607e3dd1
Add Replay integration for dev e2e tests (#40955)
<!--
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 that you're making:
-->

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have a helpful link attached, see `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`
- [ ] Integration 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`

## Documentation / Examples

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

@ijjk moving this here.

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-09-29 14:45:10 -07:00
Steven
53f0e2b31c
Update image tests files from *.js to *.ts (#39663)
Let's utilize typescript for our tests
2022-08-16 23:29:55 +00:00
JJ Kasper
135a4cfc66
Add handling for prefetching onTouchStart and initial mobile testing (#38805)
This adds handling for prefetching `onTouchStart` as this gives a little more time to start parsing required scripts for a page transition if not already done that can help make the transition faster. This is based on research showing the touch start event firing on average `90ms` before click (x-ref: [source](https://instant.page/#:~:text=in%20the%20world.-,On%20mobile,-A%20user%20starts))

This also adds testing safari with playwright so we can run these in PRs instead of only after merge and adds initial mobile testing as well. 

x-ref: [slack thread](https://vercel.slack.com/archives/C7PDM7X2M/p1658250170774989?thread_ts=1658249275.178349&cid=C7PDM7X2M)

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `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`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `pnpm lint`
- [ ] The examples guidelines are followed from [our contributing doc](https://github.com/vercel/next.js/blob/canary/contributing.md#adding-examples)
2022-07-25 19:04:03 +00:00
Naoyuki Kanezawa
93678b569b
Do not add locale to link for api route and middleware preflight (#35994)
Fixes https://github.com/vercel/next.js/issues/33578

This PR fixes `Link` component as well to not add locale for api routes since both preflight redirect and link should work the same.

Additionally, it fixes the webdriver method `browser.waitForCondition()` for playwright to not wrap with function string.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-04-11 15:59:07 +00:00
Naoyuki Kanezawa
633050402f
fix: add locale prefix to middleware preflight url (#35911)
Fixes part of https://github.com/vercel/next.js/issues/34274

Navigating to `/` causes to redirect preflight request to a url of browser language like `/en`. 
This PR fixes to add the locale prefix always so that the redirect does not happen anymore and middleware can get a correct locale.

## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `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`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.
- [ ] Errors have helpful link attached, see `contributing.md`

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2022-04-07 11:39:49 +00:00
Jiachi Liu
00ca8df26c
test: add inline flight response reuse test (#34364)
To collect the requests starting from page load, we need to register event listeners before page loading (`page.goto` API invocation). By default webdriver will wait for hydration, so we need to register events inside `browser.loadPage` to ensure we can collect the requests before hydration is done.

### Changes
* Add `beforePageLoad` for next webdriver
* registry page `'request'` event before loading page
* update related tests for agruments change

### Usage

```js
browser = await webdriver(appPort, '/path', {
   waitHydration, // default true
   retryWaitHydration, // default false
   disableCache, // default false
   beforePageLoad, // default undefined
})

```
2022-02-15 18:53:45 +00:00
JJ Kasper
abf781f637
Allow listening for page requests in tests (#34204) 2022-02-10 18:02:38 -06:00
Klaas Landsman
b39e49eca9
Fix detection of anchor click events inside svg (#23272)
## Bug

The `nodeName` of an anchor inside an SVG equals the lowercase `a` instead of the html anchor's uppercase `A`.
This behavior can be seen in this plain js demo: https://jsfiddle.net/L2p8f4ve/28/

fixes #23252




## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added

## 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`
- [ ] Integration tests added
- [ ] Documentation added
- [ ] Telemetry added. In case of a feature if it's used or not.

## Documentation / Examples

- [ ] Make sure the linting passes

Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-02-06 20:53:03 +00:00
Steven
b9c012f49d
Fix duplicate image src causing canceled request (#33776)
In PR #26968, we added Set of loaded images that was removed in #33474 erroneously.

We still need to track loaded images since we can't rely on `img.complete`, especially if the parent uses `react-virtualized`.

Tested on https://nextjs.org/showcase
2022-01-28 23:50:36 +00:00
JJ Kasper
1d9007307f
Fix accessing router before ready for HMR ping (#31588)
* Fix accessing router before ready for HMR ping

* update test name

* lint-fix
2021-11-18 16:23:21 -06:00
JJ Kasper
7a34e5ea3c
Fix playwright trace names (#30374) 2021-10-27 00:10:26 -05:00
JJ Kasper
474f1e7d93
Add initial test trace outputs (#30246) 2021-10-25 08:21:57 +02:00
JJ Kasper
6a9cda5726
Ensure browser instances are not re-created un-necessarily (#29091) 2021-09-15 10:03:33 -05:00
JJ Kasper
a92a5caec2
Update test set-up to leverage playwright when able to (#28634)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-09-13 14:36:25 +02:00