feat: integrate Partytown with first-party proxy mode#654
Conversation
Partytown scripts now work with first-party proxying. Previously, these were completely separate code paths — Partytown bypassed bundling/rewriting and the intercept plugin couldn't reach the web worker. Three integration points: - Generate Partytown `resolveUrl` from intercept rules (web-worker equivalent of the intercept plugin) - Skip `__nuxtScripts.*` API rewrites for partytown scripts (avoids undefined reference in worker) - Auto-configure `@nuxtjs/partytown` resolveUrl when both features are enabled
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
commit: |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (7)
📝 WalkthroughWalkthroughThis pull request introduces Partytown integration support by adding a URL resolver generation mechanism and restructuring first-party configuration return values. A new Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
❓ Type of change
📚 Description
Partytown and first-party proxy mode were completely separate code paths — Partytown scripts bypassed bundling/URL rewriting, and the intercept plugin (main-thread monkey-patches) couldn't reach Partytown's web worker. This meant scripts loaded from third-party domains and all tracking requests went unproxied.
This PR integrates the two via three points:
resolveUrlgeneration — generates a PartytownresolveUrlfunction from the same intercept rules used by the main-thread intercept plugin. This is the web-worker equivalent — Partytown calls it for every network request (fetch, XHR, sendBeacon, Image) made by worker-executed scripts.skipApiRewritesfor partytown scripts — when bundling scripts for Partytown, URL string literals are still rewritten but API call rewrites (fetch→__nuxtScripts.fetch, etc.) are skipped since__nuxtScriptsdoesn't exist in the worker context andresolveUrlhandles interception instead.Auto-configuration — after
finalizeFirstParty, auto-configures@nuxtjs/partytown'sresolveUrlfrom the computed intercept rules. Warns if user already has a customresolveUrl.Flow for a partytown + first-party script
useScriptpartytown quick-path renders<script src="/_scripts/assets/bundled.js" type="text/partytown">(src already rewritten by transform)resolveUrl→ rewritten to/_scripts/p/*Changed files
src/first-party/partytown-resolve.tsgeneratePartytownResolveUrl()src/first-party/setup.tsfinalizeFirstPartyreturnsinterceptRulesalongside devtools datasrc/first-party/index.tssrc/module.tsresolveUrl, passespartytownScriptsto transformsrc/plugins/rewrite-ast.tsskipApiRewritesoption onrewriteScriptUrlsASTsrc/plugins/transform.tspartytownScriptsset, passesskipApiRewritesfor partytown scriptstest/unit/rewrite-ast.test.tsskipApiRewrites+generatePartytownResolveUrl