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.

Persisting data across multiple requests & service worker updates

See original GitHub issue

Is your feature request related to a problem? Please describe. Suppose I create an account (via the mocks) and want to log out and log back in as the new user. Is there an elegant way to persist that newly created data using MSW?

Describe the solution you’d like I think whatever solution should be agnostic to the storage method used, whether it’s a plain variable, an in-memory DB, or something else. I was thinking the most agnostic and simplest way to go about doing this is just to access whatever storage you may have when you execute your logic in the MSW routes (ex. inside rest.get handler). However, with the above approach, when the MSW worker is updated (ex. via Webpack hot reload), that state would be wiped in some cases. Another approach to avoid the data reset would be to leverage the browser cache (via service worker, such as IndexedDB), but that wouldn’t be available on server side, which would be another problem.

Was hoping to get some thoughts on how to solve the issue of a persistent data store while using MSW mocks.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:4
  • Comments:14 (14 by maintainers)

github_iconTop GitHub Comments

4reactions
kettanaitocommented, Jan 18, 2021

This is going to be addressed in a separate library. Stay tuned for the upcoming announcements.

1reaction
Aprillioncommented, Dec 6, 2020

PR for readme created (and looks linked correctly above…)

I also tried to add a test case for the readme example - but the test fails, because BroadcastChannel is not available in Node nor jsdom => see https://github.com/mswjs/live-storage/compare/master...Aprillion:test?expand=1

Read more comments on GitHub >

github_iconTop Results From Across the Web

Handling service worker updates with immediacy
Sometimes when you update a service worker, it's good to let users know. Here, you'll learn how to do just that.
Read more >
Service worker update only changed content in cache, or ...
Service worker update only changed content in cache, or share data between service workers ... I have following service worker: var files2cache = ......
Read more >
Service workers - web.dev
Service workers get updated when the browser detects that the service worker currently controlling the client and the new (from your server) version...
Read more >
Frequently asked questions - Mock Service Worker Docs
Mock Service Worker uses Service Worker API for requests interception. ... may issue occasional updates and bug-fixes to the worker script.
Read more >
Cache GraphQL POST requests with Service Worker - Medium
The solution is to implement a Service Worker to cache POST requests based on the query string in the request body and store...
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