rsnext/packages/next/lib
Houssein Djirdeh 79016b879f
Adds web worker support to <Script /> using Partytown (#34244)
## Summary

This PR adds a new `worker` strategy to the `<Script />` component that automatically relocates and executes the script in a web worker.

```jsx
<Script 
  strategy="worker"
  ...
/>
```

[Partytown](https://partytown.builder.io/) is used under the hood to provide this functionality.

## Behavior

- This will land as an experimental feature and will only work behind an opt-in flag in `next.config.js`:

  ```js
  experimental: {
    nextScriptWorkers: true
  }
  ```

- This setup use a similar approach to how ESLint and Typescript is used in Next.js by showing an error to the user to install the dependency locally themselves if they've enabled the experimental `nextScriptWorkers` flag.

  <img width="1068" alt="Screen Shot 2022-03-03 at 2 33 13 PM" src="https://user-images.githubusercontent.com/12476932/156639227-42af5353-a2a6-4126-936e-269112809651.png">
- For Partytown to work, a number of static files must be served directly from the site (see [docs](https://partytown.builder.io/copy-library-files)). In this PR, these files are automatically copied to a `~partytown` directory in `.next/static` during `next build` and `next dev` if the `nextScriptWorkers` flag is set to true.

## Checklist

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

This PR fixes #31517.
2022-03-11 22:26:46 +00:00
..
eslint collect telemetry for ESLint rules (#34564) 2022-02-24 20:43:28 +00:00
helpers Don't use yarn if a package-lock.json file is found (#31926) 2022-02-05 20:16:25 +00:00
typescript Pre-compile more dependencies continued (#32679) 2021-12-21 16:13:45 +01:00
web Implement web server as the request handler for edge SSR (#33635) 2022-01-26 06:22:11 +00:00
chalk.ts Implement web server as the request handler for edge SSR (#33635) 2022-01-26 06:22:11 +00:00
coalesced-function.ts Upgrade to Prettier 2 (#13061) 2020-05-18 15:24:37 -04:00
compile-error.ts Adds ESLint with default rule-set (#23702) 2021-04-30 11:09:07 +00:00
constants.ts Implement Middleware RFC (#30081) 2021-10-20 17:52:11 +00:00
detect-typo.ts Add CLI command typo detection (#34836) 2022-02-26 07:05:26 -08:00
fatal-error.ts Adds ESLint with default rule-set (#23702) 2021-04-30 11:09:07 +00:00
file-exists.ts upgrade to typescript 4.4.3 (#29112) 2021-09-16 18:06:57 +02:00
find-config.ts find-up 2020-03-30 16:26:25 -04:00
find-pages-dir.ts Add initial support for new env handling (#10525) 2020-03-26 13:32:41 +01:00
get-package-version.ts perf(next): use require.resolve instead of resolve (#19518) 2021-01-11 14:43:08 +00:00
get-project-dir.ts Add CLI command typo detection (#34836) 2022-02-26 07:05:26 -08:00
has-necessary-dependencies.ts [ESLint] Introduce a new setup process when next lint is run for the first time (#26584) 2021-08-04 21:53:15 +00:00
install-dependencies.ts Don't use yarn if a package-lock.json file is found (#31926) 2022-02-05 20:16:25 +00:00
interop-default.ts Add new target for middleware (#30299) 2021-10-26 18:50:56 +02:00
is-error.ts fix: fixes #33314 move is-plain-object for es5 compilation (#33690) 2022-01-27 17:59:42 +00:00
is-serializable-props.ts fix: fixes #33314 move is-plain-object for es5 compilation (#33690) 2022-01-27 17:59:42 +00:00
is-yarn.ts [ESLint] Introduce a new setup process when next lint is run for the first time (#26584) 2021-08-04 21:53:15 +00:00
load-custom-routes.ts Refactor base server to remove native dependencies (#33499) 2022-01-20 21:25:44 +00:00
non-nullable.ts temporary: re-flag font optimization (#20372) 2020-12-21 19:26:00 +00:00
oxford-comma-list.ts refactor(typescript): extract preflight functions (#13510) 2020-05-28 23:39:46 +00:00
pretty-bytes.ts Move syntax formatting to prettier (#7454) 2019-05-29 13:57:26 +02:00
recursive-copy.ts Add initial standalone build handling (#31003) 2021-11-09 11:03:20 -06:00
recursive-delete.ts Add initial standalone build handling (#31003) 2021-11-09 11:03:20 -06:00
recursive-readdir.ts Remove extraneous fs.stat calls (#27779) 2021-08-09 15:28:00 +00:00
verify-partytown-setup.ts Adds web worker support to <Script /> using Partytown (#34244) 2022-03-11 22:26:46 +00:00
verifyAndLint.ts Pre-compile more dependencies (#32742) 2022-01-17 15:17:22 +00:00
verifyTypeScriptSetup.ts Pre-compile more dependencies continued (#32679) 2021-12-21 16:13:45 +01:00
worker.ts Ensure workers are not left open (#34503) 2022-02-18 09:12:56 +00:00