-
Notifications
You must be signed in to change notification settings - Fork 62
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
getGlobalState loses sync with useGlobalState after 0.17 #33
Comments
Thanks for reporting. I will take a look. It can be tough. |
I think I get it now. 8565e67 Would you tell me your use case? I'd like to see if/how we can solve or mitigate it. |
@dai-shi has been trimmed down a bit, but basically:
const authMiddleware = new ApolloLink((operation, forward) => {
// This sets the headers for my API queries
operation.setContext({
headers: getAuthHeaders(getGlobalState('authUser')),
});
if (!forward) {
return null;
}
return forward(operation);
});
// This is the client used by queries, with headers
const client = new ApolloClient({ link: ApolloLink.from([ authMiddleware ]) });
const LayoutSwitcher = () => {
const [authUser] = useGlobalState('authUser');
// This decides what view to render based on if im authenticated or not
return authUser !== null ? <AppLayout /> : <AuthLayout />;
};
const AppLayout = () => {
// This uses apollo client, and query requires the authentication it provides
// However, I am thrown 401 Unauthorized by API (in 0.17 only)
const { data } = useQuery(gql`some query`);
return <div>stuff</div>;
}; |
Thanks! I totally understand how this is happening. Please give me some time for this. This is tricky... |
@Slessi So, here's bad news for your use case. First of all, it's all fine with React Sync Mode and v0.16. v0.17 is for React Concurrent Mode. #31 Now, I can only think of two options (apart from using v0.16) for your use case.
The first option doesn't sound nice, because it's against CM and the code will be hacky. I wonder how Apollo Client will deal with CM, but I don't think it will accept apollo link config from state. So, it's probably the right way to store auth information outside React. Not sure, will see. I will keep think about any workaround to bridge this gap. Hope it explains to some extent. Questions are welcome. |
#34 reopened. |
After updating to
0.16
->0.17
,getGlobalState
returns the old state value after a change.useGlobalState
seems fineThe text was updated successfully, but these errors were encountered: