Commit graph

201 commits

Author SHA1 Message Date
Shu Ding
91a6e3af3a
Do not hide body when concurrentFeatures is enabled (#31187)
When Fizz is enabled, we want to always show the content of body even before it's loaded. Please hide whitespace changes when reviewing this PR.

## 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`
2021-11-09 00:45:44 +00:00
Jiachi Liu
cfb8cc841e
Change .web extension of document page to part of path (#31116)
Fixes: #31104

This effecting users who are using expo with next (`@expo/next-adapter`) since react-native use `.web`, `.ios` and `.android` to identify platform. [Reference](https://docs.expo.dev/guides/using-electron/#%F0%9F%A7%B8-behavior)

Change `document.web.js` to `document-web.js` as fallback page in web runtime
2021-11-07 22:14:50 +00:00
Gerald Monaco
ad981783ab
Add render prop support to <Main> (#30156)
Adds support for render props to the `<Main>` component, when using the [functional custom `Document`](https://github.com/vercel/next.js/pull/28515) style. This allows you to write something like this:

```tsx
export default function Document() {
  const jsxStyleRegistry = createStyleRegistry()
  return (
    <Html>
      <Head />
      <body>
        <Main>
          {content => (
            <StyledJsxWrapper registry={jsxStyleRegistry}>
              {content}
            </StyledJsxWrapper>
          )}
        </Main>
        <NextScript />
      </body>
    </Html>
  )
}
```

In functional document components, this allows the `<App>` to be wrapped, similar to `enhanceApp` (which is only available via `getInitialProps`, which is not supported by functional document components). The primary use for this is for integrating with 3rd party CSS-in-JS libraries, allowing them to attach an `useFlush` handler to [support React 18](https://github.com/reactwg/react-18/discussions/110):

```tsx
import { unstable_useFlush as useFlush } from 'next/document'

export default function StyledJsxWrapper({ children, registry }) {
  useFlush(() => {
    /* ... */
  })
  return (
    <StyleRegistry registry={registry}>
      {children}
    </StyleRegistry>
  )
}
```

Support for `useFlush` will be added in a follow up PR.
2021-11-07 17:36:39 +00:00
Jiachi Liu
0c494af97c
Use absolute document and app paths for the middleware SSR loader (#30963)
* use absolute path

* use absolute path

* update test

* rename modern -> web

Co-authored-by: Shu Ding <g@shud.in>
2021-11-04 14:10:07 -05:00
JJ Kasper
a25c1dd15a
Add warning for large amount of page data (#29956)
Co-authored-by: Steven <steven@ceriously.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-10-25 21:07:05 +02:00
Kara
5760ceac86
Refactor Document to prep for classic streaming (#29834)
This refactor is the first of a few changes to support "classic" (two-part)
streaming. This one should be a noop that doesn't actually change the behavior.
It re-organizes the way that functions are wrapped in Document Head/NextScript
so anything that will be part of the second flush can be separated out from the
first flush. It also adds the structure for a useMaybeDeferContent hook, but
currently always assumes that nothing should be deferred.

The next PRs will actually implement streaming.
2021-10-13 17:07:18 -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
Jiachi Liu
57d9076e58
Adopt context based experimental styled-jsx version (#28646)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2021-09-09 10:13:50 +02:00
Janicklas Ralph
26255a685d
Add data attribute to script component (#28310)
Add data attribute `data-nscript` to the script component
2021-08-20 20:48:48 +00:00
JJ Kasper
5544adc481
Update to latest babel versions (#28174) 2021-08-17 09:18:08 +02:00
Gerald Monaco
08a24780b0
Clean up Document in preparation for streaming (#28032)
We generate the HTML for a document in two steps: First, we generate the body (i.e. everything under `<div id="__next">`). Then we generate the rest of the document and embed the body in it.

This doesn't work when the body is a stream, because React can't render the body for us unless we buffer it, and buffering it means not streaming. This PR takes the existing approach for AMP and uses it for all scenarios: instead of rendering HTML, we just render a placeholder that we can replace with HTML later. This will be used in a follow-up PR to let us know where to concatenate the body stream.

I also used the opportunity to split out `HtmlContext` from `DocumentProps`, as these will not be the same thing with functional document components.
2021-08-13 03:36:54 +00:00
JJ Kasper
fa01a1593e
Update client error to show link in console (#27789)
* Update client error to show link in console

* Apply suggestions from code review
2021-08-05 10:38:06 -05:00
Tim Neutkens
c7e2a1df6a
Use SWC for Next.js core client files (#27196)
Replaces Babel with SWC for Next.js core client-side files.

## 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-07-28 15:10:51 +00:00
Steven
f1e6bc9e6b
Rename next/script interface Props to ScriptProps (#26990)
This will ensure `next/script` follows the same naming convention as `next/image`. For example:

```js
import Image, { ImageProps } from 'next/image'
import Script, { ScriptProps } from 'next/script'
```

Fixes #26290
2021-07-07 16:35:50 +00:00
Paweł Tymczuk
3b592e206e
Fix: added the key property to the pre next scripts (#26646)
This fixes the React warning: `Warning: Each child in a list should have a unique "key" prop.` that is thrown when using the `Script` components with the `beforeInteractive` strategy. 

Fixes: #26618
2021-07-02 20:23:11 +00:00
Tim Neutkens
5b9ad8da90
Move next-server directory files to server directory (#26756)
* Move next-server directory files to server directory

* Update tests

* Update paths in other places
2021-06-30 13:44:40 +02:00
Tim Neutkens
136b754396
Move code shared between server/client to "shared" folder (#26734) 2021-06-30 11:43:31 +02:00
Janicklas Ralph
66d1d53a3e
Enable optimized loading strategy (#26021)
Enable optimized Loading strategy by default
2021-06-12 11:26:47 +00:00
JJ Kasper
1628e6d16c
Update client-side default error (#25997)
Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
2021-06-11 16:23:45 +02:00
Janicklas Ralph
b05719f928
Remove experimental tag from Script component (#25435)
* Remove experimental tag from Script component

* update size tests

* Update size

* Update size limit

* Update basic output sizes

Co-authored-by: Tim Neutkens <tim@timneutkens.nl>
Co-authored-by: Tim Neutkens <timneutkens@me.com>
2021-06-03 13:56:50 +02:00
Tim Neutkens
ed3e8f7125
Remove deprecated features (#25446)
* Remove deprecated features

In the next major version we'll want to merge this PR that removes some of the long-time deprecated features, it'll have a positive effect on bundle size.

* Update tests

* Update tests

* Change unsized to layout=fill in test

* Update sizes

* Update rotation test

* Update size limit test

* Update test

* Update test

* Update test
2021-06-02 10:11:03 -05:00
Janicklas Ralph
58a4482f75
Font optimization add preconnect (#25346) 2021-06-02 11:43:03 +02:00
Janicklas Ralph
eaf74c1cb8
Improving script loading strategy (#24939) 2021-05-13 12:39:36 +02:00
Janicklas Ralph
b859c5bdf5
Refactor scriptloader option names (#25012) 2021-05-12 13:37:57 +02:00
Janicklas Ralph
86827058e4
Refactor experimental-script component (#24940) 2021-05-10 10:39:08 +02:00
Tim Neutkens
cf4ba8d705
Upgrade eslint to the latest version (#24377)
## Bug

- [ ] Related issues linked using `fixes #number`
- [ ] 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
2021-04-25 18:34:36 +00:00
Joe Haddad
079c629165
experimental: remove legacy plugin system (#20759)
* chore: remove old plugins implementation

* chore: remove `onErrorMiddleware`

* Reduce allowed middleware

* remove collect plugins file

* remove old tests

* remove old demo packages
2021-04-22 14:03:13 -05:00
Tobias Koppers
08baf526ff
improve react-loadable-plugin (#24281)
Co-authored-by: JJ Kasper <jj@jjsweb.site>



## Bug

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


Closes: https://github.com/vercel/next.js/issues/22741
2021-04-21 11:18:05 +00:00
Janicklas Ralph
8fdcc52854
Font optimization (#21676)
Enable font optimization by default
2021-04-05 17:47:03 +00:00
Tim Neutkens
b34a0c98fa
Update err.sh links to use nextjs.org/docs/messages instead (#23353) 2021-03-29 10:25:00 +02:00
Janicklas Ralph
a107dcb732
Experimental script loader changes (#22038)
Making experimental script work in _document.js - Fixes for server to client transition
Adding additional test for _document.js
2021-03-02 19:17:33 +00:00
Tim Neutkens
56b149f7be
Add experimental per-page option to disable JS preloads (#21329)
As discussed with @csswizardry. This is a temporary option in case you know the preloads are not needed. It will likely be a default once the ScriptLoader work from @janicklas-ralph has been proven in partner apps and landed.

```js
// pages/index.js
export const config = {
  unstable_JsPreload: false
}
```
2021-01-19 19:38:15 +00:00
Alex Castle
74909ecfd4
Move CSS Preloads to top of head at document render (#18864)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-12-30 17:12:46 -05:00
Joe Haddad
52270af307
Remove unnecessary unfetch polyfill for dev (#20589)
Fetch is always polyfilled in legacy browsers by `@next/polyfill-nomodule`, so we do not need to import unfetch for IE11 support.

Fixes #20588
2020-12-29 21:01:42 +00:00
Juny
5cabe5e220
fix: set empty document files for amp first (#16934)
Fixes: https://github.com/vercel/next.js/issues/16926

I do not know this is the right way.
Please review it.
2020-12-22 03:18:01 +00:00
Joe Haddad
260ab51974
temporary: re-flag font optimization (#20372)
There's currently two bugs with the font optimization, but we'd really like to ship a stable version.

To unblock the stable release, we're **temporarily** reflagging this. It'll be unflagged on canary again!
2020-12-21 19:26:00 +00:00
Prateek Bhatnagar
57e156bc49
Making font optimization as default (#19758)
- Making font optimizations as default
- Re-enabling tests
- Fixes #19159
2020-12-04 09:52:54 +00:00
Janicklas Ralph
c8cd77a856
Script loader component (#18281) 2020-12-01 19:10:16 +01:00
Janicklas Ralph
6e4632efe1
Css optimizations (#16539)
Co-authored-by: JJ Kasper <jj@jjsweb.site>
2020-12-01 19:02:07 +01:00
Joe Haddad
30c2dfdc47
Remove old modern mode experiment (#19275)
This PR removes the modern mode experiment because:

- It does not yield meaningful bundle size wins when compared to other initiatives we've taken
- It's not compatible with webpack 5 (which we're upgrading to)
- It's currently broken and causes most apps to malfunction
- There's no champion currently owning the experiment

We can re-introduce this in the future when we'd like to make it a default for all Next.js apps.

Note: **Next.js still supports Differential Loading (`nomodule`) and does it by default.** This PR strictly removes the experimental modern _syntax_, and does not disable our existing modern/legacy polyfilling.

---

Fixes #19200
Fixes #18960
Fixes #14707
Fixes #14465
2020-11-18 18:30:00 +00:00
Steven
318a1bf309
Add "nonce" from <Head> to the injected <style> to satisfy CSP (#19150)
Fixes #18557
2020-11-13 20:29:16 +00:00
Gerald Monaco
80671273ca
Revert "Remove next-head-count (#16758)" (#18713)
Co-authored-by: Joe Haddad <joe.haddad@zeit.co>
2020-11-10 16:35:47 -05:00
Will Heslam
b3d9fd2a0d
Make getInlineScriptSource arg Readonly (#17281)
The rule [total-functions/no-unsafe-readonly-mutable-assignment](https://github.com/danielnixon/eslint-plugin-total-functions#total-functionsno-unsafe-readonly-mutable-assignment) triggers with this error message:
> Assigning a readonly type to a mutable type can lead to unexpected mutation in the readonly value

when invoking
```
      NextScript.getInlineScriptSource(this.props)
```
inside a `_document.tsx`'s render function.
due to `this.props` having the type:
```
props: Readonly<P> & Readonly<{ children?: ReactNode }>
```
in `@types/react`

On the other hand, this is a small, low-priority change (IMO), so an alternative work around is just to disable the lint rule for that line of course.

Lint, tests, and build passes.

Lint error was discovered using typescript@next, version `4.1.0-dev.20200921` and eslint-plugin-total-functions version `4.1.0`, but I tested the change to nextjs using typescript version `3.8.3`.
2020-11-05 12:03:45 +00:00
khades
b1503e13e8
Fix dynamic css unloading (#17173)
Serverside Dynamically loaded CSS module file insertion adds css-files as usual static files with special data-n-p tag, that is used in page transition logic. That files get removed on page transition cause they are not explicitly required in scope of page.

Mini-css-extract-plugin adds style tags at chunk insertion without any tags and leave them be, no matter how many page transitions were made.

I removed data-n-p tag from dynamically loaded css module files and added new data-n-d tag for it.

Fixes #16950
2020-11-03 05:23:31 +00:00
Tasuku Uno
9dfc9ebc8a
Fix css dependency in /_error (#17301) 2020-10-21 12:11:18 +02:00
JJ Kasper
b2d1d87e7f
Add initial changes for i18n support (#17370)
This adds the initial changes outlined in the [i18n routing RFC](https://github.com/vercel/next.js/discussions/17078). This currently treats the locale prefix on routes similar to how the basePath is treated in that the config doesn't require any changes to your pages directory and is automatically stripped/added based on the detected locale that should be used. 

Currently redirecting occurs on the `/` route if a locale is detected regardless of if an optional catch-all route would match the `/` route or not we may want to investigate whether we want to disable this redirection automatically if an `/index.js` file isn't present at root of the pages directory. 

TODO: 

- [x] ensure locale detection/populating works in serverless mode correctly
- [x] add tests for locale handling in different modes, fallback/getStaticProps/getServerSideProps

To be continued in fall-up PRs

- [ ] add tests for revalidate, auto-export, basePath + i18n
- [ ] add mapping of domains with locales
- [ ] investigate detecting locale against non-index routes and populating the locale in a cookie

x-ref: https://github.com/vercel/next.js/issues/17110
2020-10-07 21:11:01 +00:00
Gerald Monaco
039eb817e1
Remove next-head-count (#16758)
Removes `next-head-count`, improving support for 3rd party libraries that insert or append new elements to `<head>`.

---

This is more or less what a solution with a `data-` attribute would look like, except that instead of directly searching for elements with that attribute, we serialize the elements expected in `<head>` and then find them/assume ownership of them during initialization (in a manner similar to React's reconciliation) based on their properties.

There are two main assumptions here:
1. Content is served with compression, so duplicate serialization of e.g. inline script or style tags doesn't have a meaningful impact. Storing a hash would be a potential optimization.
2. 3rd party libraries primarily only insert new, unique elements to head. Libraries trying to actively manage elements that overlap with those that Next.js claims ownership of will still be unsupported.

The reason for this roundabout approach is that I'd really like to avoid `data-` if possible, for maximum compatibility. Implicitly adding an attribute could be a breaking change for some class of tools or crawlers and makes it otherwise impossible to insert raw HTML into `<head>`. Adding an unexpected attribute is why the original `class="next-head"` approach was problematic in the first place!

That said, while I don't expect this to be more problematic than `next-head-count` (anything that would break in this new model also should have broken in the old model), if that does end up being the case, it might make sense to just bite the bullet.

Fixes #11012
Closes #16707

---

cc @Timer @timneutkens
2020-09-09 01:41:04 +00:00
Joe Haddad
6895f9b0f4
Replace <link rel=stylesheet> client-side transitions with <style> tags (#16581)
This pull request replaces our client-side style transitions with `<style>` tags over async `<link rel=stylesheet>` tags. This should fix some edge cases users see with Chrome accidentally causing a FOUC.

This also removes the need to perform an async operation before starting the render, which should remove any perceivable navigation delay.

---

Fixes #16289
2020-08-26 16:34:53 +00:00
khades
1a7f3e5199
Store css file dependencies info for dynamic imports and apply it at SSR (#12843)
To prevent FOUC, discussed in #10557 i need to store information about css file dependencies for chunk. Right now current implementation just throws away everything but js.

Can there be more than one css file in chunk? If no - code will be simplified.

closes #10557
2020-08-24 05:20:11 +00:00
JJ Kasper
a7550bf1d7
Add error when document component isn't rendered (#16459)
If a custom `_document` is added but not all of the expected document components are rendered it can cause unintended errors as noticed in https://github.com/vercel/next.js/issues/10219 so this adds detecting when one of the expected document components isn't rendered and shows an error. 

Closes: https://github.com/vercel/next.js/issues/10219
2020-08-24 02:42:51 +00:00