Commit graph

2375 commits

Author SHA1 Message Date
Gal Schlezinger
e251a8b2d8
Add test for multiple cookies coming from middleware (#34465)
This PR adds a test that ensures that we can set multiple cookies in a middleware response
2022-02-18 20:35:22 +00:00
Javi Velasco
8752464816
Allow reading request bodies in middlewares (#34294) (#34519)
This PR brings back @Schniz awesome contribution to bring in bodies to middleware. It was reverted to leave it out of the stable release and to have some time to test it out in canary before officially releasing it. This PR is simply a `cherry-pick` of his original work.

Closes: #30953 
Closes: https://github.com/vercel/next.js/pull/34490

Co-authored-by: Gal Schlezinger <2054772+Schniz@users.noreply.github.com>
2022-02-18 19:43:43 +00:00
Gerald Monaco
204a95586d
Remove useMaybeDeferContent hook (#34506) 2022-02-18 13:07:19 -06:00
Steven
9e77ef4ec6
Fix next/image incorrectly warning for position: absolute parent (#34551)
- Fixes #33007 
- Fixes #31340
2022-02-18 18:44:32 +00:00
Jiachi Liu
ce76d1712e
Leverage existing component checking warning for streaming (#34526)
## Bug

Fixes: #31993

* Remove the simple component checking in middleware ssr
* Leverage existing components checking for Component / App / Document, if any of these component is not valid react type or is undefined nextjs will error in dev mode with redbox. Like above.

<img width="826" alt="image" src="https://user-images.githubusercontent.com/4800338/154668945-bcee24ee-17aa-4afd-acda-9f8b249891ac.png">


- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
2022-02-18 15:25:10 +00:00
Naoyuki Kanezawa
7c103fac7d
fix process polyfill on middleware (#34426)
Fixes the problem that global `process` variable has only the `env` field.
Also fixed the issue that the `env` field is empty when the `process` module is used as the value of the variable (which happens when the module is contained in a dependency of application).

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`
2022-02-18 08:39:30 +00:00
Balázs Orbán
a74af1f31d
fix: mock image path as next/image expects it (#34350)
The default mock value caused `next/image` to throw an error.

Fixes #33976

## 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-02-18 04:15:57 +00:00
Gerald Monaco
944c734d04
Add unstable_useFlushEffects hook (#34117)
Implements https://github.com/vercel/next.js/issues/30997 with some minor tweaks to the design:

* The hook is moved to Client Components (e.g. `pages/_app` instead of `pages/_document`). This was a silly oversight in the original design: the hook needs to be called during server prerendering.

* `useFlushEffects` instead of `useFlushEffect` as there isn't a particularly safe way to implement the singular semantics as a Client Component hook given the current implementation of server rendering.

---

Fixes #30997
2022-02-18 00:18:28 +00:00
Jiachi Liu
1c167afa58
rsc: clean client buffer cache after flushed (#34475)
## Bug

Fixes #34464

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Errors have helpful link attached, see `contributing.md`
2022-02-17 18:57:53 +00:00
Gal Schlezinger
f0f322c0d1
Remove deprecation for relative URL usage in middlewares (#34461)
* Remove deprecation for relative URL usage in middlewares

* fix tests

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-02-17 09:12:36 -06:00
JJ Kasper
b70397e770
Revert "Allow reading request bodies in middlewares (#34294)" (#34479)
This reverts commit 1edd8519d6.
2022-02-17 08:45:31 -06:00
JJ Kasper
42020114d2
Update font-optimization test snapshot (#34478) 2022-02-17 08:39:45 -06:00
Gal Schlezinger
1edd8519d6
Allow reading request bodies in middlewares (#34294)
Related:

- resolves #30953
2022-02-17 11:32:36 +00:00
Steven
2264d35b64
Fix .svg image optimization with a loader prop (#34452)
* Fix .svg image optimization with a `loader` prop

* Add test

* Revert test back to 266x266
2022-02-16 17:48:17 -06:00
JJ Kasper
59714db16d
Update server-only changes HMR handling (#34298)
* Update server-only changes HMR handling

* Add failing tests for GS(S)P server only changes

* update test

* normalize backslashes

* Update to xor the chunk hashes

* remove test change

* remove other test change
2022-02-16 16:32:24 -06:00
Steven
8a55612c0d
Add image config for dangerouslyAllowSVG and contentSecurityPolicy (#34431)
## Feature

- [x] Integration tests added
- [x] Documentation added
- [x] Errors have helpful link attached, see `contributing.md`



Co-authored-by: Lee Robinson <9113740+leerob@users.noreply.github.com>
2022-02-16 19:28:22 +00:00
Balázs Orbán
9639fe704c
Ensure we don't poll page in development when notFound: true is returned (#34352)
Fixes: #34342

Visiting the following page will call gSSP indefinitely in a loop and logs errors from `on-demand-entries-client`:
```js
const Home = () => null
export default Home
        
export function getServerSideProps() {
  console.log("gssp called")
  return { notFound: true }
}
```

We should not keep fetching the page if it returns 404 as  it can introduce unnecessary data requests.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`



Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-02-16 18:53:48 +00:00
Aman Mittal
634926d8df
Add Error Handing section for ISR (#34360)
* Add Error Handing section for ISR

* Apply suggestions from code review

* update check

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-02-15 14:22:15 -06: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
982b65a327
Ensure invalid request to static page is handled correctly (#34346)
* Ensure invalid request to static page is handled correctly

* update test
2022-02-15 11:28:18 -06:00
Tim Neutkens
62b1704e41
Add support for "type": "module" in package.json (#33637)
- [x] Add failing test for development / production
- [x] Add failing test for client-side JavaScript
- [x] Write `.next/package.json` with `"type": "commonjs"
- [x] Fix issue with client-side JavaScript showing `module` is not defined

Production works after these changes. Development breaks on module not existing because of the Fast Refresh loader. Working with @sokra to add alternatives to what is being used in the loader to webpack so that it can be updated.

Fixes #23029, Fixes #24334



## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] 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-02-15 16:24:11 +00:00
Alex Castle
f516304649
Remove experimental image optimization feature (#34349)
This PR removes the experimental `optimizeImages` flag. This feature was designed to automatically add preload tags for images, but I was never able to get it to do a very good job of selecting the images that actually need preloading.

This feature never graduated from experimental and in fact we never even publicized it as an experimental feature for people to try.

Additionally, even if someone was using this feature, it wouldn't have a functional effect, only a performance effect (removal of some preloads).

For those reasons, I believe it is safe to remove this functionality and that it is not a breaking change.
2022-02-15 01:36:51 +00:00
Shu Ding
2f7951892e
fix double render in strict mode (#34333)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-02-14 22:35:05 +01:00
Shu Ding
468833e0b4
Fix <RouteAnnouncer/> shouldn't announce initial path under strict mode and React 18 (#34338)
As the comment mentioned, React 18 with Strict Mode enabled might cause double invocation of lifecycle methods. This makes the `<RouteAnnouncer/>` being non-empty for the initial page, which is a bug (it should only announce page change whenever a navigation happens).

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] 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-02-14 19:18:39 +00:00
Jiachi Liu
1aee93581f
Align reactRoot config between server and webpack config (#34328)
### Changes

* node server and webpack should share the same logic: auto detect react 18 and enable `reactRoot`
* fallback `_error` should use functional document if concurrent rendering is enabled

### Test

* Remove the hard code `reactRoot: true` in test suite
* Test some react-18 test suite with nodejs runtime
2022-02-14 16:18:57 +00:00
Shu Ding
931666dd3c
Fix uncaught error in getInitialProps when runtime is set to nodejs (#34228)
This PR ensures that the test "should render 500 error correctly" doesn't break when `runtime` is set to `nodejs` with `serverComponents` enabled.

This test case is now moved to the "basic" suite to ensure it doesn't break in both runtimes. And "should not bundle external imports into client builds for RSC" is enabled for the `nodejs` runtime too.

## Bug

- [ ] Related issues linked using `fixes #number`
- [x] 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-02-11 18:30:39 +00:00
Jiachi Liu
477134d8c9
Enable dynamic HTML in minimal mode (#34222)
Follow up for #34068

Let minimalMode render HTML by streaming facilities
2022-02-11 17:43:39 +00:00
JJ Kasper
abf781f637
Allow listening for page requests in tests (#34204) 2022-02-10 18:02:38 -06:00
Jiachi Liu
4f8ffed4bf
Fix reuse of inline flight response and 404 for RSC in node runtime (#34202)
### Fixes

* We need give value for `__flight__` query or it will lost in node runtime
* Match the cache key of flight response (`path + search`, `route, `id`)
* Flight response should return `200` instead of `404` for 404 page

### Tests

* Run rsc for node runtime test suite
* Add more cases for 404
2022-02-10 21:13:52 +00:00
Balázs Orbán
46e32ae184
feat: copy .env file in standalone mode (#34143)
Ref: #33897

I took a naive approach and simply added `.env` to the files that need to be copied.

Do we want to include `.env.production` as well? Ref: https://nextjs.org/docs/basic-features/environment-variables#loading-environment-variables

(I haven't tested what happens if the file does not exist on copy.)

Other files like `.env.*local` or `.env.{test,development}` don't make sense to copy.

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


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-02-10 17:48:14 +00:00
Simon Knott
abf9f75821
Fix bug with "Circular Structure" error (#23905)
* Fix bug with "Circular Structure" error

Since `-1` is truthy, every JSON.stringify error is mistaken to be `circular structure`. This commit fixes that behaviour, so that other errors like `Do not know how to serialize Bigint` (see https://github.com/blitz-js/babel-plugin-superjson-next/issues/63) aren't swallowed.

* Add integration test

This may be thought of as being a pretty contrived example, but it's exactly what happened in https://github.com/blitz-js/babel-plugin-superjson-next/issues/63.

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-02-09 20:28:24 -06:00
Maia Teegarden
01ee7e0b22
Chore/stable swc compiler options (#34074)
Mark some previously experimental swc compiler options as stable under a new `compiler` option

## 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-02-10 01:54:28 +00:00
Jiachi Liu
52c3d07c95
Fix required files matching in rsc (#34137)
Fix the wrong filename evaluation of `MIDDLEWARE_FLIGHT_MANIFEST` in required files. Besides checking the generated files, check if they're declared correctly in `required-server-files.json`
2022-02-09 19:24:05 +00:00
JJ Kasper
28f65ff411
Fix image-optimizer requires in next-server (#34141) 2022-02-09 12:37:55 -06:00
Jiachi Liu
0f5d9dce72
Fix included flight manifest on node runtime (#34113)
We need to switch to json flight manifest on node deployment for RSC
2022-02-09 01:26:50 +00:00
JuniorTour
e2d6c311b5
fix: next/image usage from node_modules (#33559)
fix: image config not work for `node_modules`

Co-authored-by: Steven <steven@ceriously.com>
2022-02-08 19:55:53 -05:00
JJ Kasper
130f8645a2
Update to leverage response-cache for image-optimizer (#34075)
This updates to leverage our `response-cache` used for ISR for our `image-optimizer` as well. 

Co-authored-by: Steven <steven@ceriously.com>
2022-02-08 18:46:59 -05:00
JJ Kasper
3f0a8d9057
Update failing tests from upstream resource (#34110)
Seems these were failing from https://example.com randomly 404ing

x-ref: https://github.com/vercel/next.js/runs/5113528980?check_suite_focus=true#step:8:1465
x-ref: https://github.com/vercel/next.js/runs/5095808948?check_suite_focus=true
x-ref: https://github.com/vercel/next.js/runs/5086862695?check_suite_focus=true
2022-02-08 23:03:20 +00:00
Jiachi Liu
fb80055a1f
fix: arrow function export in rsc client component (#34105)
The `export default xxx` statement is slightly different from estree when exporting an arrow function instead of identifier in swc.
We also need to capture arrow exports.
2022-02-08 19:09:47 +00:00
Shu Ding
dd7962d788
Fix functions manifest test (#34092)
We should remove `.next` after checking the manifest file here.

## 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-02-08 15:53:35 +00:00
Tim Neutkens
40329a70a5
Add check for resolveWeak to next/dynamic (#33908)
Fixes #33476

I've added the test for this but it passes either way, even when the change to loadable.js is not made. On the reproduction I was able to reproduce it consistently and it's fixed with this change. 



## 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-02-08 14:02:53 +00:00
Shu Ding
6944074506
Deprecate concurrentFeatures with runtime (#34068) 2022-02-08 14:16:46 +01:00
JJ Kasper
7cd9de34da
Add api-utils helper for testing (#34078) 2022-02-07 21:50:23 -06:00
11koukou
d4b29db8c7
Fix lazyRoot functionality for next/image (#33933)
Fixed lazyRoot functionality (#33290). Changed the unique id for Intersection Observers discrimination since previously they were only identified by the different rootMargins, now each being identified by the rootMargin and the root element as well
Added more Images to the test with different margins and with/without lazyRoot prop. Browser correctly initially loading two of the four Images according to the props' specifications.

Co-authored-by: Steven <steven@ceriously.com>
2022-02-07 10:46:16 -05:00
Tim Neutkens
c74e4f21ff
Add support for async fn / promise in next.config.js/.mjs (#33662)
- Add support for async function / promise export in next.config.js/.mjs
- Update docs

Adds support for https://twitter.com/timneutkens/status/1486075973204422665

But also the simpler version:

```js
module.exports = async () => {
  return {
    basePath: '/docs'
  }
}
```



## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] Integration tests added
- [ ] Errors have helpful link attached, see `contributing.md`

## Feature

- [x] Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [x] Documentation added

## Documentation / Examples

- [ ] Make sure the linting passes by running `yarn lint`
2022-02-07 08:48:35 +00:00
Wouter Raateland
b49717f8db
Allow scroll prevention on hash change (#31921)
* Allow scroll prevention on hash change

Currently, `scrollToHash` is performed on every hash change, even when this change is caused by `<Link scroll={false} {...props} />`.
This change prevents scrolling in this case and allows users to specify the desired scrolling behavior in the router's `hashChangeComplete` event.

* Add test case and apply fixes

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2022-02-06 18:38:55 -06:00
Adam Pietrasiak
41706d6fd3
Require component rendered as child of Link to pass event to onClick handler (#27723)
Currently, if you render `next/link` like

```ts
<Link>
  <CustomComponent />
</Link>
```

and have 

```tsx
interface Props {
  onClick?: () => void; // <— note we're not passing event as an argument
}

function CustomComponent({ onClick }: Props) {
  return <div onClick={() => onClick?.()}>Hello</div>
}
```

It'll result in error

```
link.js?f421:21 Uncaught TypeError: Cannot read property 'defaultPrevented' of undefined
```

<!--
Thanks for opening a PR! Your contribution is much appreciated.
In order 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 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


Co-authored-by: JJ Kasper <22380829+ijjk@users.noreply.github.com>
2022-02-07 00:04:37 +00: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
Yubin
6090101581
Place 'charset' element at the top of <head> (#28119) 2022-02-06 13:51:51 -06:00
Alexander Akait
65e951e412
fix: data url handling in css-loader (#34034) 2022-02-06 11:10:14 -06:00