Skip to content

fix(web-studio): normalize service worker scope - #3963

Open
ranxi2001 wants to merge 1 commit into
volcengine:mainfrom
ranxi2001:fix/studio-service-worker-scope
Open

fix(web-studio): normalize service worker scope#3963
ranxi2001 wants to merge 1 commit into
volcengine:mainfrom
ranxi2001:fix/studio-service-worker-scope

Conversation

@ranxi2001

Copy link
Copy Markdown
Contributor

Description

Studio reused its slashless router base path as the service worker scope. In
the standard /studio/ deployment, browsers therefore rejected
/studio/service-worker.js with scope /studio, and the rejected registration
promise was left unhandled.

This change derives a dedicated slash-terminated scope for service worker
registration while leaving the router base path unchanged. Registration
failures are caught and logged with context.

Human Involvement

  • A human participated in the implementation or review loop
  • This PR was generated entirely by AI agents without human participation in the loop

Related Issue

Fixes #3959

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • Performance improvement
  • Test update

Changes Made

  • Normalize service worker script URLs and scopes for root and nested deployments.
  • Catch and log registration failures instead of leaving a rejected promise unhandled.
  • Add focused regression tests for path normalization and registration outcomes.

Testing

  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have tested this on the following platforms:
    • Linux
    • macOS
    • Windows

Commands run:

npm test -- src/lib/service-worker.test.ts
npm test
npm run lint
npm exec -- tsc --noEmit --strict --skipLibCheck --target ES2022 --module ESNext --moduleResolution bundler --lib ES2022,DOM src/lib/service-worker.ts
npm run build -- --base=/studio/
npm exec -- prettier --check src/main.tsx src/lib/service-worker.ts src/lib/service-worker.test.ts
git diff --check upstream/main...HEAD

The production /studio/ bundle was also exercised in Playwright Chromium. As
a control, the old { scope: '/studio' } call raised the reported
SecurityError; the patched bundle registered /studio/service-worker.js at
scope /studio/ with no page error.

Checklist

  • My code follows the project's coding style
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • Any dependent changes have been merged and published

Screenshots (if applicable)

Not applicable.

Additional Notes

The repository-wide TypeScript check still reports existing errors in unchanged
source and generated client files. The new helper passes a focused strict
TypeScript check. Repository-wide Prettier also reports three unchanged files;
all files changed by this PR pass Prettier.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

[Bug]: Studio registers service worker with invalid /studio scope and leaves rejection unhandled

1 participant