Only store persistable state on unmount #105
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Currently we write to persistable state on each change to any persistable state including the current query and variables as well as some the resizable elements of the UI. This suggests replacing that with only saving persistable state when the component is about to unmount.
This fixes a problem where opening multiple instances of GraphiQL at the same time can result in one query appearing across all views. Now, only the last window closed will save the query. This also fixes a frustration where accidentally closing a tab and then editing another instance of GraphiQL renders the accidentally closed tab harder to recover.
This also fixes a performance issue where setting into storage can be slightly expensive and we were performing this on every keystroke.
The primary drawback is the potential for lost state in the case of an unexpected browser cache, since this no longer saves to persistable state optimisitically. I believe that's worth the gains and a minor issue relative to the accidental tab-closing issue.