worker-bundler: host-side assets, no DO wrapper, SW preview proxy#1145
Merged
threepointone merged 5 commits intomainfrom Mar 22, 2026
Merged
worker-bundler: host-side assets, no DO wrapper, SW preview proxy#1145threepointone merged 5 commits intomainfrom
threepointone merged 5 commits intomainfrom
Conversation
Change createApp to return assets separately for host-side serving instead of embedding asset modules/runtime in the isolate. Remove generated asset runtime and durable-object wrapper generation; server bundle is returned directly (mainModule/modules) and assets + assetManifest are provided for the host to serve via handleAssetRequest/createMemoryStorage. Update README, add design doc (design/worker-bundler.md), adjust the playground and tests to use handleAssetRequest and createMemoryStorage, and simplify the build script by removing the asset runtime bundling step. Also remove the generated _asset-runtime-code artifact from .gitignore.
Add an embeddable service worker (PREVIEW_SW) that rewrites same-origin requests to the preview prefix and claim clients on activation. Serve the SW at /preview/:name/sw.js and inject an idempotent navigator.serviceWorker.register script into HTML responses so iframes auto-register the SW and reload once it takes control. Remove the prior HTML attribute rewrites and runtime fetch/XHR patching in favor of the scope-based SW approach, and preserve original response headers/status when returning the modified HTML.
Made-with: Cursor
🦋 Changeset detectedLatest commit: 8a4b4e6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
Made-with: Cursor
The delay-0 alarm would auto-fire between RPC calls, causing getStatus() to hit a destroyed DO. Use a future delay so the alarm only fires when runDurableObjectAlarm triggers it manually, and return status from the scheduling call itself to avoid the race. Made-with: Cursor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Separate assets from the isolate.
createAppreturnsassets,assetManifest, andassetConfigfor host-side serving instead of embedding asset content, manifest, and the ~1000-line asset-handler runtime inside the dynamic isolate. The caller useshandleAssetRequest()+createMemoryStorage()(both already exported) to serve assets before forwarding to the isolate. The isolate only contains the user's server code.Remove DO wrapper code generation. The
durableObjectoption anddurableObjectClassNameresult field are gone, along withgenerateAppWrapper,generateDOAppWrapper,generateAssetPreamble, and the_asset-runtime-code.tsbuild step.createAppreturns the user's server bundle asmainModuledirectly — how it's mounted (module worker, DO class, facet) is the caller's concern.Replace preview proxy with Service Worker. The 70-line HTML rewriting + fetch/XHR monkey-patching block is replaced by a 7-line Service Worker that intercepts all requests from the preview iframe and rewrites URLs. Catches everything the old approach missed (CSS
url(), dynamicimport(),EventSource, etc.). One-time reload on first visit per preview.Add design doc at
design/worker-bundler.mdcovering the two key architectural decisions and their tradeoffs.Net: -249 lines across the package, simpler build, cleaner separation of concerns.
Test plan
npm run checkpasses (sherif, exports, formatting, linting, typecheck across 65 projects)Made with Cursor