Commit graph

3818 commits

Author SHA1 Message Date
Emilio Cobos Álvarez
05a732eb7a
Remove useless getComputedStyle call. (#27969)
See https://github.com/w3c/csswg-drafts/issues/6501 to see how I found this.

This line doesn't recompute layout in browsers, because `"height"` is given as a pseudo-element name rather than a property.

The right way to do what it wants is `getComputedStyle(document.body).height`, but given nobody noticed this (and this is generally never needed, manually triggering layout should never be needed to avoid FOUC) it seems better to keep current behavior and just remove the call.
2021-09-20 03:03:36 +00:00
JJ Kasper
5b963422c0
Fix array query value has matching (#29216) 2021-09-19 20:32:30 -05:00
Flo
76dee14db4
Fix #11107 - don't prefetch preloaded modules (#22818)
This PR proposes a fix for https://github.com/vercel/next.js/issues/11107 (JS modules are loaded twice). A more detailed explanation of the investigation that led to this PR can be found in the issue's comments (https://github.com/vercel/next.js/issues/11107#issuecomment-791780168).

## Replicability

To identify that the issue replicates on any given project, you need to 
1. look at the network tab (first/clean load of site, so preferably ⌘+⇧+R on an incognito tab), 
2. sort by "name", and filter requests by `mime-type:application/javascript` (selecting "JS" in the devtools filters will actually show all "script" types, but ignore all "javascript" types)
3. look for pairs of identical calls with one originating from initial HTML (`preload` of priority "high" originating from "(index)" or "([page name])")  and another one from a script (`prefetch` of priority "lowest" originating from a .js file), where neither of the files is served from the cache.

Here's a screenshot of an example of what to look for:
<img width="601" alt="Screen Shot 2021-03-07 at 09 59 18" src="https://user-images.githubusercontent.com/1325721/110234627-cf1c6d00-7f2b-11eb-9cd7-749bf881ba56.png">


The issue was reproduced easily on the following projects:
- On [nextjs.org](https://nextjs.org/) where duplicates add up to ~70kB of transferred javascript out of 470kB (14.9%).
- On [vercel.com](https://vercel.com/) where duplicates add up to ~105kB of transferred javascript out of 557kB (18.8%).
- On [tiktok.com](https://tiktok.com/en) where duplicates add up to ~514kB of transferred javascript out of 1556kB (33%).
- In my own project using `"next": "^10.0.1"` (private repo) where duplicates add up to about 5% of total transferred javascript.
- In the issue's comments, a developer reported a replication using `"^10.0.7"` on a [public repo](https://github.com/SidOfc/sidneyliebrand.io).


## Some information about the fix

- Both `preload` and `prefetch` values for `<link rel="x">` behave similarly, with the difference being in network priority level (preload is high priority, prefetch is lowest priority).

- Next.js uses `<link rel="preload">` in its initial HTML but then *only* uses `<link rel="prefetch">` for the rest of the lifetime of the page. 

- However, when Next.js detects that a script should be requested in advance, it only checks for matching `<link rel="prefetch">` and not `<link rel="preload">` (which have higher priority and are present earlier in the DOM, thus have a greater likelihood of being already loaded). 

This PR aims to fix that oversight.

## Potential issues (none AFAIK)

As far as I can tell by looking through the codebase, **there is no downside** not to add a `prefetch` when a `preload` is already in the DOM. No other script looks for a `<link>` based on its `rel` attribute.
2021-09-19 17:51:04 +00:00
Andrew Hurle
88f27ef947
Fix bug where returning { notFound: true } from GSP broke next export (#24481)
* Fix bug where returning `{ notFound: true }` from GSP broke `next export`

We could just as easily omit the notFoundRoutes check, but I didn't want
to mask other potential bugs that would result in missing files

* update check

* move check

Co-authored-by: jj@jjsweb.site <jj@jjsweb.site>
2021-09-18 10:20:45 -05:00
jj@jjsweb.site
f579767e60
v11.1.3-canary.24 2021-09-17 15:00:16 -05:00
Tobias Koppers
797dabe351
add support for new URL() (#28940)
Currently `new URL()` for server assets is completely broken because of the `publicPath` that is used for them too. `new URL()` for SSR is broken on windows as it's using absolute urls on the windows filesystem. And `new URL()` is using an incorrect filename

* Place all `asset`s correctly in `/_next/static/media` with `[name].[hash:8][ext]`
* Added a separate runtime chunk for api entries, without `publicPath`
* Introduce separate layer for api entries, which uses server-side URLs.
* Otherwise new URL() will return a faked relative URL, that is identical in SSR and CSR
* Disables react-refresh for api entries

Fixes #27413



## 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`
- [x] 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
2021-09-17 19:20:09 +00:00
Tobias Koppers
e3c6739ee0
make code consistent with babel externals (#28867)
* make code consistent with babel externals

* update compiled

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-09-17 12:27:03 -05:00
Tobias Koppers
fa9ee197a4
suggest incremental typescript for typescript >= 4.4.2 (#29169)
This is now safe to enable since it no longer causes performance regressions
2021-09-17 15:42:27 +00:00
Tim Neutkens
367f8d6e6d v11.1.3-canary.23 2021-09-17 09:35:40 +02:00
Tim Neutkens
002ed25087
Add name to invalidated span (#29170) 2021-09-17 09:34:37 +02:00
Tim Neutkens
84ce15bba5 v11.1.3-canary.22 2021-09-16 19:48:00 +02:00
Tim Neutkens
3e8f470e49
Ensure traces are flushed in development when there is an error (#29149) 2021-09-16 19:43:28 +02:00
Maia Teegarden
16a737d9b5
Update expected test output (#29146) 2021-09-16 11:52:16 -05:00
Tobias Koppers
d78bb6fe46
upgrade to typescript 4.4.3 (#29112)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-09-16 18:06:57 +02:00
JJ Kasper
cefd9cf283
Add crawler blocking for fallback: true (#29121)
* Add crawler blocking for fallback: true

* update test

* Update check

* Add note to docs

* use browser agent for non-crawler test
2021-09-16 11:01:28 -05:00
Tim Neutkens
e98690c307 v11.1.3-canary.21 2021-09-16 17:13:46 +02:00
Tim Neutkens
2ac5e1c1f0
Build next-swc binaries (#29144)
Co-authored-by: timneutkens <timneutkens@users.noreply.github.com>
2021-09-16 17:12:08 +02:00
강동윤
81c5511b74
next-ssg: Don't inject __N_SSP for files without server props. (#29141) 2021-09-16 16:26:38 +02:00
Tim Neutkens
10daef9607
Ensure Next.js dist files are commonjs compatible with swcLoader enabled (#29138)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-09-16 16:11:30 +02:00
Tim Neutkens
60560a941d v11.1.3-canary.20 2021-09-16 15:48:46 +02:00
Tim Neutkens
c39b7d19bd
Update next-swc binaries (#29140)
Co-authored-by: timneutkens <timneutkens@users.noreply.github.com>
2021-09-16 15:47:46 +02:00
강동윤
2c82615bde
Fix transform of ` in styled-jsx (#29136) 2021-09-16 15:08:42 +02:00
Tim Neutkens
c491adfe12 v11.1.3-canary.19 2021-09-16 08:59:20 +02:00
Tim Neutkens
172a536c61
Update next-swc binaries (#29132)
Co-authored-by: timneutkens <timneutkens@users.noreply.github.com>
2021-09-16 08:58:36 +02:00
Maia Teegarden
c6cec752c7
Fix partial one off global selectors (#29128) 2021-09-16 08:16:10 +02:00
JJ Kasper
e313398468
Update trace ignores for next import (#29119) 2021-09-15 15:00:52 -05:00
Tim Neutkens
1f788b5430
Development tracing improvements (#29076) 2021-09-15 20:06:24 +02:00
JJ Kasper
85b8399856
Remove log from failing to parse source map (#29118)
This removes the log when we fail to parse the source maps in the `wellknown-errors-plugin` since this log isn't really actionable by users and clutters the error output. 

x-ref: https://github.com/vercel/next.js/issues/27783#issuecomment-915654054
2021-09-15 17:53:22 +00:00
Janicklas Ralph
73408211aa
Remove inert font tag in font optimization (#28869)
* Remove inert font tag in font optimization

* Fix lint

* Remove inert font tag during font optimization

* Fix lint

* Fix lint

* Fix lint

Co-authored-by: JJ Kasper <jj@jjsweb.site>
2021-09-15 11:43:13 -05:00
Tim Neutkens
4b41b48a8e v11.1.3-canary.18 2021-09-15 17:34:32 +02:00
Tim Neutkens
ae305f6aa9
Update styled-jsx (#29103)
Includes a fix for when a tree is rendered without the styled-jsx registry being provided. It'll noop in this new version.

## 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
2021-09-15 14:19:20 +00:00
Tim Neutkens
ca27e34167 v11.1.3-canary.17 2021-09-15 09:32:44 +02:00
Maia Teegarden
4a2d5a1b49
Add/styled jsx swc (#29005)
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: Tim Neutkens <timneutkens@me.com>
2021-09-15 09:24:31 +02:00
jj@jjsweb.site
2cfdc68650
v11.1.3-canary.16 2021-09-14 16:05:21 -05:00
JJ Kasper
49c99cc323
Fix host segment replacing for custom routes (#29090)
This fixes segments inside of the host of the destination failing to parse with url.parse due to the unexpected colon by escaping the colon for segments and then unescaping them after we have parsed the URL.

## Bug

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

x-ref: https://github.com/vercel/vercel/pull/6713
2021-09-14 20:13:46 +00:00
Tim Neutkens
7d664d5b36
Add stats config for SWC (#28883)
* Add stats config for SWC

* Remove stats for deprecated mode

* Include native binaries in local linking

* Expose minify in next-swc

* Build next-swc binaries

* Only upload changed binary artifact

* Build next-swc binaries

* Expose minify in js binding

* Use new minify function in terser plugin

* Build next-swc binaries

* Build next-swc binaries

* Build next-swc binaries

* Pass pagesDir option to SWC for next/dynamic

* Build next-swc binaries

* Add spans for next-trace-entrypoints-plugin

* Fix linting

Co-authored-by: Maia Teegarden <dev@padmaia.rocks>
Co-authored-by: padmaia <padmaia@users.noreply.github.com>
Co-authored-by: timneutkens <timneutkens@users.noreply.github.com>
2021-09-14 18:13:11 +02:00
Tobias Koppers
0e29a2d08f
reload the page to show 404 when receiving invalid event from on-demand-entries (#29074) 2021-09-14 17:11:00 +02:00
Jeff Wen
07fe406bd5
Add crossOrigin type to the NextConfig (#29033) 2021-09-14 09:51:10 -05:00
Maia Teegarden
a784d54ab5
Fix/upload binary artifact (#29069)
* Fix upload of binary artifacts

* Build next-swc binaries

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-09-13 16:40:06 -07:00
Kara
41484f62cc
Throw error if res is accessed after gSSP returns (#29010)
* Throw error if res is accessed after gSSP returns

Currently it's possible to access the `ServerResponse` through `context.res`
in `getServerSideProps()`. If one was to store that response and mutate
its headers or status code after gSSP returns (e.g. during rendering), it
would currently happen to work because of when headers are sent. However,
this is an anti-pattern that relies an implementation detail of the framework
and shouldn't be allowed. This will be particularly important once Next.js
starts to support basic streaming (two-part flush: routing then data) because
then the headers will be sent as soon as gSSP returns, which explicitly breaks
this pattern.

With this commit, the framework now throws an error in development mode if
the ServerResponse is accessed after gSSP returns.

* fixup! Throw error if res is accessed after gSSP returns
2021-09-13 17:10:46 -05:00
JJ Kasper
e49829bb8e
Fix webpack version and safari test and update compiled (#29059)
* Fix webpack version and safari test and update compiled

* Update compiled again
2021-09-13 10:56:07 -05:00
Tim Neutkens
c1e5f5b260
Make traces in development reliable (#28990)
Co-authored-by: Jiachi Liu <inbox@huozhi.im>
2021-09-13 15:49:29 +02: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
강동윤
fd2af1422d
next/dynamic: Accept pagesDir (#29055)
* Add pages_dir

* Add `pages_dir` to `next/dynamic` pass

* Dep

* Fix next/dynamic psss

* Fix

* Update test refs

* Add a test
2021-09-13 13:37:07 +02:00
강동윤
c38e702347
Make next-ssg optional (#28862)
Co-authored-by: Tim Neutkens <timneutkens@me.com>
2021-09-13 12:20:38 +02:00
Tim Neutkens
9572b30849
Deprecate webpack 4 support (#28840) 2021-09-13 09:18:04 +02:00
Maia Teegarden
0d0f34ba18
Pass code as buffer to swc minify (#29009)
This should fix this: https://github.com/vercel/next.js/pull/28883/checks?check_run_id=3560578176#step:4:353



## 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
2021-09-11 00:57:01 +00:00
Gerald Monaco
1f99c3009f
Use Writable instead of Observable (#29007)
Use `Writable` instead of `Observable` and remove the `zen-observable` dependencies. I initially opted to use `Observable` for simplicity and fast iteration, but we should really just use `Writable` directly (or some other stream in the future).

React's streaming SSR has some [specific requirements](https://github.com/reactwg/react-18/discussions/66#discussioncomment-944266) on the stream API. Rather than trying to also squeeze a `Readable` in here, which might be more standard for node apps, I've just followed React's lead. By limiting ourselves to just `Writable`, it ought to be easier to adopt a different stream type in the future if desired.

The React `pipeToNodeWritable` API requires us to pass a stream immediately, but we don't actually have a `ServerResponse` to give it until `RenderResult.pipe(...)` is called later. For that reason, we pass React a `Writable` that we will simply forward to `res` later. This mechanism of deferring is `NodeWritablePiper`, which is just a function that can be called with `ServerResponse` (or another `Writable`, as we now do to render to string for static results) to have content written to it. `NodeWritablePiper` takes a `next` argument so that we can chain both synchronous and asynchronous pipers together.

Also does some clean up and adds another streaming test for backpressure.
2021-09-11 00:17:56 +00:00
Kara
c27e3a41dc
Update gSSP type to support props as a promise (#28999)
In a previous PR, `getServerSideProps` was altered to support returning
`props` as a promise. This change updates the TS types to permit promises
as well, so you can write type `GetServerSideProps<Props>` instead of
`GetServerSideProps<Promise<Props>>`. e.g.:

```typescript
type Props = {
  data: string
}

export const getServerSideProps: GetServerSideProps<Props> = async (
  context
) => {
  return {
    props: (async function () {
      return { data: 'some data' }
    })(),
  }
}
```

## Feature

- [x] 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`
- [x] 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`
2021-09-10 19:36:40 +00:00
Tim Neutkens
5fed96dd88 v11.1.3-canary.15 2021-09-10 11:20:55 +02:00