Skip to content

test: add hydration-level coverage for onRehydrateStorage (#129) - #143

Merged
cybermax4200 merged 2 commits into
ecotask-network:mainfrom
chidii:test/129-rehydrate-coverage
Aug 30, 2026
Merged

test: add hydration-level coverage for onRehydrateStorage (#129)#143
cybermax4200 merged 2 commits into
ecotask-network:mainfrom
chidii:test/129-rehydrate-coverage

Conversation

@chidii

@chidii chidii commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

Summary

Investigated #129 and couldn't reproduce the described bug. Zustand v4's
persist middleware documents onRehydrateStorage as:

(state) => (state?, error?) => void

The outer function runs once pre-hydration; its return value is invoked
again post-hydration with the hydrated state. That's exactly the shape
currently implemented in prefsStore.ts, and it does run — it's not dead
code.

Reference: https://zustand.docs.pmnd.rs/reference/middlewares/persist

What this PR does

Adds hydration-level test coverage that exercises the actual registered
onRehydrateStorage callback (via persist.getOptions()), rather than
re-simulating it. No production code changes.

Covers the acceptance criteria from #129:

  • A stored notificationPrefs missing PROOF_TIMEOUT results in
    PROOF_TIMEOUT: true after rehydration.
  • A stored notificationPrefs with REWARD_CONFIRMED: false preserves
    that value (not overwritten by defaults).
  • An empty stored-prefs object falls back to full defaults.
  • The error path (postRehydrationCallback(undefined, error)) is a no-op.

All four pass against the current, unmodified prefsStore.ts.

Why not the originally-proposed fix

The issue proposes collapsing onRehydrateStorage to a single-argument
(state) => {...} form. That would actually break rehydration: Zustand
would call it once with the pre-hydration state and never invoke it
again after the persisted data loads, so mergeNotificationDefaults would
stop running entirely — a regression, not a fix.

Out of scope

@cybermax4200 cybermax4200 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the ci checks

@chidii

chidii commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

@cybermax4200 ci fixed, please merge

@cybermax4200
cybermax4200 merged commit cfea418 into ecotask-network:main Aug 30, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants