Skip to content

fix(js): bundle worklets in-process so no esbuild service outlives the build - #5353

Merged
kixelated merged 2 commits into
mainfrom
fix/worklet-inline-esbuild
Oct 13, 2026
Merged

kixelated merged 2 commits into
mainfrom
fix/worklet-inline-esbuild

Conversation

@kixelated

@kixelated kixelated commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

js/common/vite-plugin-worklet.ts bundled each ?worklet entry with esbuild's build(), which starts esbuild's long-lived service process. Nothing stopped it, so it outlived vite build. Once the parent exited it was orphaned and reaped by init, so its CPU (about 0.6s) never reached the build's process accounting, and a stray process lingered after the build.

Approach

Bundle with rolldown, the bundler Vite 8 already loads, through rolldown() + generate() + close(). It runs in-process, so there is no child to leave behind. Vite's own ?worker handling nests rolldown builds inside a build the same way.

  • Output is unchanged in kind: one ES chunk (codeSplitting: false), minified for builds only, and the alias option maps to resolve.alias. The three worklets come out the same size or smaller.
  • The worklet consumers (@moq/watch, @moq/publish, demo/boy, demo/web, and the audio-quality and interop JS clients) swap their esbuild devDependency for rolldown at ^1.2.12, the version Vite 8.3.2 resolves, so the lockfile keeps one copy. esbuild stays in the tree for sh/size and worklet-matrix.

Tests:

  • New builds leave no child process behind in js/common/worklet.test.ts: runs a Vite build through the plugin, then asserts pgrep -P <test pid> lists nothing. It fails on main, where the esbuild service is still a live child of the test process, and passes here. bun test runs the file's tests in one process, so the esbuild child an earlier build leaves also fails it.
  • Checked by hand: vite build of @moq/watch emits assets/render-worklet.js; a dev server serves ?worklet-blob; in headless Chromium, the render and capture worklets load through audioWorklet.addModule and the capture worker starts, both as blob URLs and as hosted files. Warm vite build times match esbuild's (about 250 to 390ms on a loaded machine).
  • just check passes.

Impact

  • No public API or wire change. Build tooling only: published bundles still inline or emit the same worklets.
  • devDependencies: esbuild is replaced by rolldown in the six packages above.

Alternatives

  • esbuild.stop() after building: it sends SIGTERM and returns without waiting, so a parent that exits next can still orphan the child. It also stops the service for every other esbuild user in the process.
  • buildSync: on Node it runs the same long-lived service, hosted in a worker thread, so a child is still left behind.

Follow-ups

  • A release backport is on fix/worklet-inline-esbuild-release. It is a hand port, since release still has workletInline and no worklet test.

(Written by Claude Opus 5.5)

🤖 Generated with Claude Code


View with [code]smith Autofix with [code]smith
Need help on this PR? Tag @codesmith-bot with what you need. Autofix is disabled.

…e build

The worklet Vite plugin bundled with esbuild's build(), which starts esbuild's
long-lived service process. Nothing stopped it, so it outlived `vite build` and
was reaped by init, taking its CPU out of the build's accounting.

Bundle with rolldown, the bundler Vite 8 already runs, which works in-process
and leaves no child behind. The worklet consumers swap their esbuild
devDependency for rolldown at Vite's resolved version.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-12T14:58:51.849958Z 4b5bf77 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@coderabbitai

coderabbitai Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 27 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used all 4 included reviews currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 46517aeb-b400-4039-8f44-4d0d49aff84f
📥 Commits

Reviewing files that changed from the base of the PR and between 4b5bf77 and 9ebd7c1.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • demo/boy/package.json
  • demo/web/package.json
  • js/common/vite-plugin-worklet.ts
  • js/common/worklet.test.ts
  • js/publish/package.json
  • js/watch/package.json
  • test/audio-quality/clients/js/package.json
  • test/interop/clients/js/package.json

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: c2bf7c1b-9294-479c-baf3-374315b6992d
📥 Commits

Reviewing files that changed from the base of the PR and between 9050086 and 4b5bf77.

⛔ Files ignored due to path filters (1)
  • bun.lock is excluded by !**/*.lock
📒 Files selected for processing (8)
  • demo/boy/package.json
  • demo/web/package.json
  • js/common/vite-plugin-worklet.ts
  • js/common/worklet.test.ts
  • js/publish/package.json
  • js/watch/package.json
  • test/audio-quality/clients/js/package.json
  • test/interop/clients/js/package.json

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 0 remain after this review.

Walkthrough

Development dependencies replace esbuild with Rolldown in several packages. The worklet plugin generates a browser-targeted ES module, returns the first output’s code, and closes the bundle. A new integration test checks whether child processes remain after the build and temporary-directory cleanup.

Priority: ➖ Normal

Merge Risk: ⚪ Minimal · up to 4b5bf

No confirmed issue currently prevents merging after normal checks.

Pre-merge checks | Passed 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: replacing out-of-process esbuild worklet bundling with in-process bundling to prevent lingering services.
Description check Passed The description directly explains the problem, implementation, affected dependencies, testing, and impact of the changeset.
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. (6 skipped: 6 …
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
✨ Simplify code
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@kixelated

Copy link
Copy Markdown
Collaborator Author

Merge summary:

(Written by Claude Opus 5.5)

@kixelated
kixelated added this pull request to the merge queue Oct 13, 2026
Merged via the queue into main with commit c32f2ee Oct 13, 2026
7 of 8 checks passed
@kixelated
kixelated deleted the fix/worklet-inline-esbuild branch October 13, 2026 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant