Skip to content
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

Store doesn't persist data after rebuilding it when logging out #111

Open
high-performance-hery opened this issue Feb 18, 2022 · 12 comments

Comments

@high-performance-hery
Copy link

high-performance-hery commented Feb 18, 2022

When logging out, we rebuild a new environment like this:

    const store = new Store(recordSource, persistOptionsStore, relayStoreOptions)
    const env = new Environment(
        {
            network,
            store,
        },
        {}
    )

but the issue is that mutations aren’t updating the store until we hard restart the app.

Is there anythign specific we need to do when logging out?

@high-performance-hery high-performance-hery changed the title Store doesn't persist after rebuilding it when logging out Store doesn't persist data after rebuilding it when logging out Feb 18, 2022
@morrys
Copy link
Owner

morrys commented Feb 18, 2022

Hi @high-performance-hery,
It appears that the restore of the new environment is not performed

@high-performance-hery
Copy link
Author

We do call useRestore with the newly built environment, is there anything else we need to do?

@morrys
Copy link
Owner

morrys commented Feb 21, 2022

Add the log to understand if the new environment has been restored and if the mutation is performed in the new enrivonment

@morrys
Copy link
Owner

morrys commented Feb 21, 2022

Otherwise, create a small sample project where the problem occurs so that I can help you

@high-performance-hery
Copy link
Author

So the new environment has been restored and the mutation is performed in the new environment.

However it looks like the first mutation updates the store correctly, but the UI doesn't get updated. So subsequent mutations just send the same mutation as the initial one and no more updates occur.

After restarting the app, mutations behave normally.

So it looks like we set up the Relay store and environment correctly, but there's an issue with the way we hook up the UI?

@morrys
Copy link
Owner

morrys commented Feb 22, 2022

I tried to modify the example project by adding a button that makes a new "login" and everything seems to work correctly.
https://github.com/morrys/offline-examples/blob/master/relay/todo-updater/js/app.js#L106

@high-performance-hery
Copy link
Author

Looks good, thanks! It looks like a setup issue on our end: queries go to the old store and mutations go to the new one, which is why the UI doesn't update when the store updates.

@high-performance-hery
Copy link
Author

high-performance-hery commented Feb 22, 2022

Is there a store property we can watch in the logs to differentiate them? I'm currently using relay-devtools to watch which store events go througgh but it isn't the most convenient

@high-performance-hery
Copy link
Author

Do I need to update the RelayEnvironmentProvider on logout? Doing this via a state update is tricky, since there is a place where I need to use our logout function imperatively (i.e. outside a component render function). Previously I had just been clearing async storage/access token and running buildEnvironment. Is there a workaround in this case?

@morrys
Copy link
Owner

morrys commented Feb 25, 2022

Yes you have to update it, otherwise the application does not log out completely, in fact it uses the enviroment associated with the old user.

It is difficult for me to give you advice on how to do this in your case.

@high-performance-hery
Copy link
Author

Yea sounds quite specific to our setup.

Would there be a problem with updating the env when logging in or signing up rather than logging out?

@morrys
Copy link
Owner

morrys commented Mar 1, 2022

No problem, but you must avoid that the application uses the old environment in the meantime

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

No branches or pull requests

2 participants