question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Stopping and starting MSW will cause multiple "instances"

See original GitHub issue

Describe the bug

I have a use case where only I start MSW when user selects “development” data. First time it works fine, but if the user logs out and in again, i.e. stopping and starting MSW, then now it’ll return twice requests twice. It will also write “Mocking enabled” twice. Basically every time I stop and start MSW it adds an extra instance.

Environment

  • msw: 0.19.3
  • nodejs: 13.11.0
  • yarn: 1.22.4

Microsoft Edge: Version 83.0.478.50

To Reproduce

  • Start a worker.
  • Call .stop() on that worker.
  • Start a new worker.

Expected behavior

Expected mocking to only be enabled once

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
marcosvega91commented, Jun 23, 2020

Yes I can give you an hand 😄

1reaction
marcosvega91commented, Jun 23, 2020

I have tried nextjs example but I don’t see the problem there, I have only one log for [MSW] Mocking enabled. Hot reload should be good if we work locally but how we can handle manual stop and start of the worker?

We should add two logic maybe:

  1. as you said hot-reload should remove all listeners
  2. stop() should remove listeners too
Read more comments on GitHub >

github_iconTop Results From Across the Web

Eye on Ethics - Social Work Today Magazine
In short, social workers must avoid abandoning clients. Abandonment is a legal concept that refers to instances when a professional is not available...
Read more >
use() - Api - Mock Service Worker Docs
use(). Prepends given request handlers to the current server instance. Request handler added after the initial setupServer call is referred to ...
Read more >
Social Worker Burnout: 8 Self-Care Tips
Caring for others can lead to social worker burnout. Here are 8 tips for social workers to take better care of themselves in...
Read more >
Chapter 5: Social Work Practice Settings - Pressbooks
Indirect practice is generally when the social worker is involved in activities that consist with facilitating change through programs and policies. This type ......
Read more >
6 Important Theories in Social Work & 6 Practice Models
That ensures competence in social work, which can increase social worker ... Social work theory provides a starting point for social workers to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found