-
Notifications
You must be signed in to change notification settings - Fork 2k
Support User: Bypass localForage while active to avoid conflicts across sessions #3977
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
dcdfe89
to
ef62496
Compare
@gwwar After a lot of trial and error, what we chatted about earlier worked 😃 Would you mind taking a look at this solution? Basically to solve the issues with the fact that
After this change, it should even be possible to remove some of the changes introduced in #3879, as the Redux store would no longer need to know about the support user state. Instead, because |
// original user/vice versa. | ||
// Copied with modifications from localForage source: localforage/test/dummyStorageDriver.js | ||
|
||
var dummyStorage = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
const
4d1dc6c
to
b582f51
Compare
describe( 'length', () => { | ||
const length = () => localForage.length(); | ||
const expectLength = ( expected ) => { | ||
return () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be nested?
d284ee5
to
2d348c9
Compare
This now uses the changes that landed in #4114 to bypass localForage on startup. Here's an overview of how we overcame the async issue described above: |
} ); | ||
const localForagePromise = localforage.defineDriver( localforageBypass ) | ||
.then( () => { | ||
localforage.config( config ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Edit: my bad, failed to switch over to the other branch properly
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, that's weird, are you seeing a Cannot bypass localforage after initialization
error in the console?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh 😄
Bypasses localForage while support user is active. This allows sync-handler and other persistent data stores using localForage to use a 'sandboxed' temporary in-memory store while support user is active, avoiding conflicts with the original user's persisted data. This doesn't cover instances of direct localStorage usage - see #3941 which covers that.
The goal is to eventually move all direct localStorage usage to localForage.
This still needs some more testing, but overall it's working.
localforage-bypass.js
was copied and modified from a localForage testing module;we can likely cut quite a bit of cruft out of it as a lot of the logic relates to test facilitation.(cruft removed in 4c39e79)Things to test:
support-user
feature flag disabledwpcom_user_bootstrap
enableddevelopment
environmentdevelopment
cc @retrofox @gwwar