You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(localstorage): strip base from watched keys and ignore keys outside it - #854
The localstorage driver's storage event listener passes ev.key to the watch callback without applying base. With base: "app", a write to user:1 from another tab is reported as app:user:1, and writes to unrelated keys outside base are reported too. Other driver methods (getItem, getKeys, clear) already add or strip base.
This change:
Ignores storage events for keys outside base.
Strips the base: prefix before the driver calls the callback.
The behavior is unchanged when no base is set. session-storage reuses this driver and gets the same fix.
Tests
The existing watch localstorage and unwatch localstorage tests now dispatch the key that localStorage actually holds (test:s1:random_file, because the test driver uses base: "test"). They still expect the watcher to receive s1:random_file.
New test watch ignores keys outside of base dispatches other:random_file and expects no event.
Without the source change, all three tests fail. With it, they pass. pnpm build, pnpm test:types, pnpm vitest run and pnpm lint pass.
Summary by CodeRabbit
Bug Fixes
Local-storage watchers now ignore events outside the configured base and report matching keys without the base prefix. Update and remove event classification remains unchanged.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Advanced
Run ID: 31e8b4e7-af91-4d6b-b08e-a5721265703b
📥 Commits
Reviewing files that changed from the base of the PR and between b33715a and 2f1a599.
📒 Files selected for processing: 2
src/drivers/localstorage.ts
test/drivers/localstorage.test.ts
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
The local-storage watcher now filters storage events by the configured base. It reports accepted keys without the base prefix. Tests cover matching and non-matching event keys, and unwatch behavior.
Changes: Base-aware watcher
Layer / File(s)
Summary
Filter and report storage events src/drivers/localstorage.ts, test/drivers/localstorage.test.ts
The watcher ignores event keys outside the configured base and removes the base prefix from accepted keys. Tests cover namespaced keys, ignored keys, and unwatch behavior.
Matching local-storage events are reported with base-relative keys, while events outside the configured base are ignored. No actionable merge-blocking risk remains.
Pre-merge checks: 5
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title clearly and concisely describes the main change: stripping the configured base from watched keys and ignoring keys outside that base.
Linked Issues check
Issue [#853] requires localstorage and session-storage watchers to respect base. The listener now accepts only keys with the normalized base: prefix and reports the key without that prefix. It…
Out of Scope Changes check
The pull request changes only the localstorage watcher implementation and its focused tests. The implementation change directly supports [#853]. The test updates and new regression test are supporting…
Docstring Coverage
No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2…
Full details: Linked Issues check
Explanation
Issue [#853] requires localstorage and session-storage watchers to respect base. The listener now accepts only keys with the normalized base: prefix and reports the key without that prefix. It preserves the full key when no base is configured. session-storage reuses this driver. The tests cover prefixed event keys, unprefixed callback keys, and ignored outside-base keys.
Full details: Out of Scope Changes check
Explanation
The pull request changes only the localstorage watcher implementation and its focused tests. The implementation change directly supports [#853]. The test updates and new regression test are supporting changes. No unrelated production behavior or unrelated files changed.
Full details: Docstring Coverage
Explanation
No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 2 files.
✨ Finishing Touches: 💡 1
🛠️ Fix failing CI checks: 💡
Commit to this branch
Create a new PR
🧪 Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
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
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.
resolves #853
The
localstoragedriver'sstorageevent listener passesev.keyto the watch callback without applyingbase. Withbase: "app", a write touser:1from another tab is reported asapp:user:1, and writes to unrelated keys outsidebaseare reported too. Other driver methods (getItem,getKeys,clear) already add or stripbase.This change:
storageevents for keys outsidebase.base:prefix before the driver calls the callback.The behavior is unchanged when no
baseis set.session-storagereuses this driver and gets the same fix.Tests
watch localstorageandunwatch localstoragetests now dispatch the key thatlocalStorageactually holds (test:s1:random_file, because the test driver usesbase: "test"). They still expect the watcher to receives1:random_file.watch ignores keys outside of basedispatchesother:random_fileand expects no event.Without the source change, all three tests fail. With it, they pass.
pnpm build,pnpm test:types,pnpm vitest runandpnpm lintpass.Summary by CodeRabbit