Skip to content

fix service worker assets not loading on gateway with help of Claude#1331

Merged
joshunrau merged 2 commits intoDouglasNeuroInformatics:mainfrom
joshunrau:devel
Apr 2, 2026
Merged

fix service worker assets not loading on gateway with help of Claude#1331
joshunrau merged 2 commits intoDouglasNeuroInformatics:mainfrom
joshunrau:devel

Conversation

@joshunrau
Copy link
Copy Markdown
Collaborator

@joshunrau joshunrau commented Apr 2, 2026

Interactive instruments use a Service Worker to serve static assets. On first load, the SW was registered but not yet controlling the page, so fetch events weren't intercepted and static assets failed to load. A refresh was required to make them work.

Fixed by:

  • Adding skipWaiting() and clients.claim() in the worker so it takes control of the page immediately on activation
  • Waiting for the controllerchange event in the bootstrap to ensure the SW is controlling the page before rendering
  • Using a MessageChannel to confirm the worker has stored the static assets before proceeding with render

Summary by CodeRabbit

  • Chores

    • Bumped version to 1.13.6
  • Improvements

    • Enhanced service worker initialization with improved controller detection
    • Strengthened service worker lifecycle management through install and activate handlers
    • Improved static asset communication using message-based protocols between the app and service worker

@joshunrau joshunrau merged commit f64d645 into DouglasNeuroInformatics:main Apr 2, 2026
1 of 2 checks passed
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 419e4cd7-c377-4091-9c43-1c6bfde7a20c

📥 Commits

Reviewing files that changed from the base of the PR and between c51defd and 81723c2.

📒 Files selected for processing (3)
  • package.json
  • packages/runtime-internal/src/interactive/bootstrap.js
  • packages/runtime-internal/src/interactive/worker.js

Walkthrough

Version bump to 1.13.6. Service worker initialization refactored from promise chains to async/await with MessageChannel-based communication. Service worker now implements lifecycle handlers that skip waiting on install and claim clients on activate, with a message handshake protocol for static asset synchronization.

Changes

Cohort / File(s) Summary
Version Bump
package.json
Updated package version from 1.13.5 to 1.13.6.
Service Worker Initialization & Communication
packages/runtime-internal/src/interactive/bootstrap.js, packages/runtime-internal/src/interactive/worker.js
Refactored bootstrap to use async/await with MessageChannel for service worker communication. Added service worker lifecycle handlers (install/activate). Implemented bidirectional message handshake for static assets synchronization via MessagePort.

Sequence Diagram(s)

sequenceDiagram
    participant Main as Main Thread
    participant SW as Service Worker
    participant Port as MessagePort

    Main->>SW: navigator.serviceWorker.ready
    SW-->>Main: ready
    
    alt controller not set
        Main->>SW: wait for controllerchange event
        SW->>SW: install → skipWaiting()
        SW->>SW: activate → clients.claim()
        SW-->>Main: controllerchange triggered
    end
    
    Main->>Main: Create MessageChannel
    Main->>SW: postMessage(STATIC_ASSETS, [port2])
    SW->>SW: Receive STATIC_ASSETS message
    SW->>SW: Store static assets
    SW->>Port: postMessage({type: 'STATIC_ASSETS_READY'})
    Port-->>Main: Receive STATIC_ASSETS_READY
    Main->>Main: Initialization complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 and usage tips.

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