Stop writing one profile's state into another - #268
Merged
Merged
Conversation
profileStorage prefixes every localStorage key with the active profile name and gets that name from a fetch on module load. These helpers are synchronous and run during render, so there is a real window on every page load where the name is not known. The old code assumed "default". A write in that window landed under default: while org-mode was active. Worse, a read moved a legacy value into the wrong profile and deleted the original: profileGet migrates an unprefixed key under the current prefix and removes it, and during the window that prefix is default:. The value the active profile owned was filed elsewhere and the original unlinked. That one does not undo itself. Both are reachable. This install has two profiles, and isDeadlineAcked runs while task cards render, well inside the window. The resolved name is now cached in localStorage and read back synchronously on the next load, which closes the window except on the first load after a switch. For that load writes are buffered and flushed once the name arrives, and the migration waits rather than guessing. useSwitchProfile records the new name before its caller reloads, closing that case too. What is left is that a read in the window can return the previous profile's value: wrong on screen for a few milliseconds, and unlike the other two it corrects itself.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
profileStorageprefixes every localStorage key with the active profile name, and gets that name from afetchon module load. These helpers are synchronous and run during render, so there is a real window on every page load where the name is not yet known. The old code assumed"default"in that window.Two things went wrong with that, and the tests that found them fail against the old code:
A write landed in the wrong profile.
profileSetduring the window wrotedefault:filterwhileorg-modewas active.A read moved a legacy value into the wrong profile, and deleted the original.
profileGetmigrates an unprefixed key under the current prefix and removes it. During the window that prefix isdefault:, so the value theorg-modeprofile owned was filed underdefaultand the original unlinked. That one does not undo itself.Both are reachable: this install has two profiles, and
isDeadlineAckedis called while task cards render, which is well inside the window.The fix. The resolved name is cached in localStorage and read back synchronously on the next load, which closes the window entirely — except on the first load after a switch, where the cache is one behind. For that load, writes are buffered and flushed once the name arrives, and the legacy migration is held back rather than guessing.
useSwitchProfilenow records the new name before its caller reloads, which closes that last case too.What is left is that a read in the window can return the previous profile's value: wrong on screen for a few milliseconds, and unlike the other two it corrects itself.
Five tests on the module, twenty in the frontend suite.
tscclean, build clean.