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

Fix issue where data would disappear after refreshing the page #1454

Merged
merged 7 commits into from
Jul 23, 2024

Conversation

jerelmiller
Copy link
Member

@jerelmiller jerelmiller commented Jul 23, 2024

Fixes #1452

#1418 did a bunch of refactoring work to reorganize how and where data was requested for the devtools. As part of that change, a GraphQL-like "server" was spun up through SchemaLink that used RPC calls to resolve data.

After refreshing the page, we'd put the devtools in a disconnected state and in doing so, would call client.resetStore. resetStore causes active queries to be refetched, and in doing so, we'd see RPC request timeouts in cases where the disconnect was caused by reloading the page since the content scripts had not yet been injected and could not receive the RPC request message. This timeout would cause the query to get put into an error mode, which would clear the query data and cause the UI to show nothing in the UI.

This fix changes to use clearStore instead of resetStore to prevent the RPC calls from firing when the content script was not yet ready to receive messages and instead will refetch the list of clients after the first client is registered again.


Ultimately I'd love to introduce a message queue so that we can queue up messages from either end of the devtools in the event the port is disconnected. Upon connecting, we can send queued messages through the queue to process them. This requires a bit more thought and work, so this fix should be sufficient for now.

@jerelmiller jerelmiller requested a review from a team as a code owner July 23, 2024 04:36
Copy link

relativeci bot commented Jul 23, 2024

#725 Bundle Size — 1.5MiB (-0.04%).

57f10ef(current) vs 043cc6c main#723(baseline)

Warning

Bundle contains 13 duplicate packages – View duplicate packages

Bundle metrics  Change 2 changes Improvement 1 improvement
                 Current
#725
     Baseline
#723
Improvement  Initial JS 1.46MiB(-0.04%) 1.46MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 92.75% 0%
No change  Chunks 5 5
No change  Assets 12 12
No change  Modules 1216 1216
No change  Duplicate Modules 51 51
No change  Duplicate Code 3.34% 3.34%
No change  Packages 182 182
No change  Duplicate Packages 10 10
Bundle size by type  Change 1 change Improvement 1 improvement
                 Current
#725
     Baseline
#723
Improvement  JS 1.46MiB (-0.04%) 1.46MiB
No change  IMG 35.85KiB 35.85KiB
No change  HTML 810B 810B
No change  Other 778B 778B

Bundle analysis reportBranch jerel/more-efficient-messagesProject dashboard

@@ -74,22 +74,28 @@ export const App = () => {
devtoolsMachine.provide({
actions: {
resetStore: () => {
apolloClient.resetStore().catch(() => {});
apolloClient.clearStore().catch(() => {});
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because this now uses clearStore instead of resetStore, active queries no longer clear out their data. This introduces a small regression where refreshing the page will show the stale data in the app until a new client is registered.

Unfortunately I've been unable to get the mounted queries to respond to cache updates after the cache has been cleared, so the data remains on screen. The refetch after the first client is registered will fix this issue.

send({ type: "connect" });
addClient(message.payload);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated addClient to use client.writeQuery to run a broadcastQueries, but unfortunately that didn't seem to have an effect on the mounted queries after clearStore was run.

This is definitely something we should look into fixing in the client as its easy for useQuery to get out-of-sync with the cache after a clearStore has been called.

Copy link
Member

@phryneas phryneas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get this fix out :)

@jerelmiller jerelmiller merged commit 837779a into main Jul 23, 2024
9 checks passed
@jerelmiller jerelmiller deleted the jerel/more-efficient-messages branch July 23, 2024 14:01
@github-actions github-actions bot mentioned this pull request Jul 23, 2024
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

Successfully merging this pull request may close these issues.

Data seems to disappear after refreshing the page
2 participants