Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add support for strategy="worker" in App Router #70212

Open
wants to merge 2 commits into
base: canary
Choose a base branch
from

Conversation

piotrski
Copy link

What?

This PR adds support for the 'worker' strategy in the <Script> component when using the App Router with nextScriptWorkers enabled. It also introduces a verification step to ensure that the Partytown component is properly set up in the root layout when using the App Router.

Why?

Previously, using strategy="worker" in the <Script> component worked in the Pages Router but not in the App Router. In the App Router, the <Script> component would fail silently without any warning or error, causing scripts intended to run in a web worker to not execute. Developers might be unaware that they need to include the Partytown component in their root layout for the setup to work correctly, and this requirement was only documented, which could be easily overlooked. This PR addresses these issues to improve developer experience and ensure consistent script handling in both routing systems.

How?

  • Script Component Update: Modified the <Script> component to handle the 'worker' strategy in the App Router by rendering a <script> tag with type="text/partytown" and passing the appropriate properties.

  • Verification Function Enhancement: Updated verifyPartytownSetup to check if the Partytown component is imported and used in the root layout file when using the App Router. If not, it logs a warning to inform the developer.

  • Bundler Setup Adjustment: Modified setup-dev-bundler to pass appDir to verifyPartytownSetup, enabling the new verification step during development.

Fixes #54431

@ijjk
Copy link
Member

ijjk commented Sep 18, 2024

Allow CI Workflow Run

  • approve CI run for commit: e3dfccd

Note: this should only be enabled once the PR is ready to go and can only be enabled by a maintainer

@piotrski piotrski marked this pull request as ready for review September 18, 2024 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants