Skip to content

Fix removed keys in persistent map restoration#73

Merged
ai merged 1 commit into
nanostores:mainfrom
rajanpanth:fix/restore-removed-map-keys
Jul 20, 2026
Merged

Fix removed keys in persistent map restoration#73
ai merged 1 commit into
nanostores:mainfrom
rajanpanth:fix/restore-removed-map-keys

Conversation

@rajanpanth

Copy link
Copy Markdown
Contributor

Summary

Remove stale persistentMap keys when storage is restored after a page-cache transition.

Problem

The pageshow restore path rebuilds the map data from its initial value and current storage, but previously updated only keys present in that rebuilt object. If a storage key was removed while the page was cached, its old value remained in the in-memory map after restoration.

Changes

  • Reuse the map's existing full-object setter during restoration so additions, updates, and removals are reconciled together.
  • Add a regression test covering an updated surviving key and a removed stale key.

Testing

  • pnpm bnt test/map.test.ts
  • pnpm exec bnt --coverage 100 --coverage-exclude "test/*"
  • pnpm test:lint
  • pnpm test:types
  • pnpm test:build
  • pnpm test:size

Before

After storage changed from { one: "1", stale: "2" } to { one: "1a" } while the page was cached, restoration produced { one: "1a", stale: "2" }.

After

Restoration replaces the map with the current initial-plus-storage state, producing { one: "1a" } and removing the stale key.

Compatibility

No public API or type changes. The correction affects only persistent-map restoration and reuses existing storage and per-key-listener reconciliation. Runtime behavior is platform-neutral.

Related issue

None; independently reproduced on the current default branch.

@ai
ai merged commit ae10cec into nanostores:main Jul 20, 2026
4 checks passed
@ai

ai commented Jul 20, 2026

Copy link
Copy Markdown
Member

Thanks. Released in 1.3.5.

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.

2 participants