feat: Add support for strategy="worker" in App Router #70212
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What?
This PR adds support for the
'worker'
strategy in the<Script>
component when using the App Router withnextScriptWorkers
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 withtype="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 passappDir
toverifyPartytownSetup
, enabling the new verification step during development.Fixes #54431