Skip to content

fix(browser): restore setupWorker lifecycle#2682

Closed
felmonon wants to merge 1 commit intomswjs:fix/define-networkfrom
felmonon:fix/define-network-browser-lifecycle
Closed

fix(browser): restore setupWorker lifecycle#2682
felmonon wants to merge 1 commit intomswjs:fix/define-networkfrom
felmonon:fix/define-network-browser-lifecycle

Conversation

@felmonon
Copy link
Copy Markdown
Contributor

Follow-up for #2650.

Summary

  • reuse the browser HTTP and WebSocket sources across worker.start() / worker.stop() cycles
  • restore the active ServiceWorkerRegistration return value on redundant worker.start() calls
  • stop service-worker keepalive traffic on worker.stop() while preserving post-stop passthrough and restart behavior
  • add browser regressions for redundant worker.start(), restart after stop, and keepalive cleanup

Testing

  • pnpm build
  • pnpm test:browser -- test/browser/msw-api/setup-worker/start/start.test.ts test/browser/msw-api/setup-worker/stop.test.ts test/browser/msw-api/setup-worker/stop/keepalive.test.ts

@kettanaito
Copy link
Copy Markdown
Member

Hi! I am super confused what you are doing here. Are there any problems you were trying to solve with these?

Also, are you using LLMs to generate your pull requests?

@felmonon
Copy link
Copy Markdown
Contributor Author

Thanks for calling that out. You're right that I should have made the problem statement much clearer.

This PR was meant to address three browser lifecycle regressions I hit on fix/define-network, relative to the current setupWorker behavior:

  • worker.stop(); worker.start() did not re-enable mocking.
  • redundant worker.start() no longer returned the active ServiceWorkerRegistration.
  • the service-worker keepalive interval continued after worker.stop().

The added browser tests were meant to lock those behaviors down.

I do use LLM tooling sometimes to help draft and iterate, but I only push changes I can reproduce and validate locally. If these behaviors are intentional on this branch, or if I'm missing the intended direction, I'm happy to close this rather than add noise.

@kettanaito kettanaito deleted the branch mswjs:fix/define-network April 6, 2026 12:29
@kettanaito kettanaito closed this Apr 6, 2026
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.

2 participants