-
Notifications
You must be signed in to change notification settings - Fork 151
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
storage fixes #1035
Merged
Merged
storage fixes #1035
Conversation
This file contains 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
samouri
force-pushed
the
fixampstate
branch
2 times, most recently
from
March 24, 2021 17:43
b365e75
to
f56b77d
Compare
samouri
commented
Mar 24, 2021
kristoferbaxter
approved these changes
Mar 31, 2021
1. StorageProcessor should accept a location key even if it has a 0-index. 2. Adds printability to GET_LOCATION messages. 3. Even though TS forbids it, consumers can be JS. So lets coerce falsy calls to empty string.
samouri
added a commit
that referenced
this pull request
Feb 22, 2022
The mutations array usually contains an index into StringContext for value of key/value in the operation. Historically, "delete" was modeled as 0th index into the array. Unfortunately, this didn't make sense if the first SET op was genuinely referring to the 0th string value (See #1035). While this fixed the first get/set operation, it also meant that deletes were no longer possible! This PR now models the delete operation as a -1 in the unsigned mutation array, corresponding to 2^16-1.
This was referenced Feb 22, 2022
samouri
added a commit
that referenced
this pull request
Feb 28, 2022
* Storage: fix clear and removeItem The mutations array usually contains an index into StringContext for value of key/value in the operation. Historically, "delete" was modeled as 0th index into the array. Unfortunately, this didn't make sense if the first SET op was genuinely referring to the 0th string value (See #1035). While this fixed the first get/set operation, it also meant that deletes were no longer possible! This PR now models the delete operation as a -1 in the unsigned mutation array, corresponding to 2^16-1. * dont rely on overflow * switch to special casing 0-value * clean up test * switch to isolating change within LocalStorage processor * jridgewell found fix
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.
summary
Fixes two bugs discovered in ampproject/amphtml#32984. Note that both fixes are only 5 LOC. The rest are tests.
AMP.getState()
is called with no args, the key was recorded as undefined in worker-thread but empty string in main-thread. The fix was to coerce falsy keys to an empty string in worker-thread as well. Without this the messages would never be matched properly and worker-thread always resolved the request withnull
.storageKey
being requested is the 0th indexed string in StringContext, the StorageProcessor would always send over null. Essentially never a problem for a dom post-hydration, but could easily happen vianodom
.As a bonus change, I've also added 'GET_STORAGE' to the list of debuggable events.