bug: devserver spawns multiple instances of web worker

Open
#3,740 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
typescript
Domain
tooling

Research direction

Start with the linked reproduction and app-root.tsx, run npm start, then save the opened source file to reproduce the dev-server reload. Trace the reload behavior and lifecycle callbacks, and confirm that repeated reloads leave only one timer and worker process without requiring a browser refresh.

Written by the indexing model from the issue text.

Description

Bug: Validated
Prerequisites
Stencil Version

2.18.1

Current Behavior

(Context)
I am trying to implement a solution where I use a web worker to periodically get messages from a backend via a websocket port.
During the development I have encountered two behaviours which seem a bit strange.

The linked repo contains a simplified version of this which reproduces the error(s)

  • If the dev server reloads it spawns a new timer (visible with the example below which will show multiple prefixes in the UI)
  • If the dev server reloads it spawns a new dedicated worker process but does not terminate the old one (visible in Google Chrome > Tools > Task Manager)
Expected Behavior
  • I would have expected that the dev server reload terminates or reuses the old worker process
  • I would have expected no additional timers (Repo contains deactivated code in app-root.tsx to cope with this)
Steps to Reproduce
  • npm start
  • open part of source (e.g. app-root.tsx) in any editor (e.g. VS Code)
  • save an opened file to trigger a devserver reload
Code Reproduction URL

https://github.com/mulztob/stencil-bug-worker-duplication.git

Additional Information
  • Both problems can be fixed by using the Browser Reload(F5)
  • On dev server reload it looks like every lifecycle hook is called except for disconnectedCallback()
Dominant language
TypeScript
Stars
13.1k
Forks
855
Avg merge
4h 7m
Merged PRs (30d)
44

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from stenciljs/core

All issues in stenciljs/core

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.