fix(core): stage preference toggles in a draft until save - #162
Merged
Merged
Conversation
toggle() committed straight to live consent state, so ticking a checkbox in a preferences panel took effect before Save: ConsentGate opened and gated scripts loaded on tick with no way to undo, and a returning visitor got a record written on every tick carrying the old decidedAt with the new decisions. toggle() now stages the flip in state.draft. Gating (has/ConsentGate), storage, and gated scripts keep reading live decisions until save() promotes the draft and stamps decidedAt; any route change that does not land on "preferences" discards the draft. Per-category granted accessors in the react/vue/svelte/solid/angular bindings read draft ?? decisions so checkboxes still respond instantly, and toggle() no longer takes ActionOptions (the record source is named at save()). Closes #157
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
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.
Summary
Fixes #157.
store.toggle()committed straight to live consent state, so ticking a checkbox in a preferences panel took effect before the user pressed Save:ConsentGateopened and gated scripts loaded on tick with no way to undo, and for returning visitors every tick wrote a record to storage carrying the olddecidedAtwith the new decisions.toggle()now stages the flip in a newConsentState.draft. Gating (has()/ConsentGate), persistence, andgateScriptkeep reading livedecisionsuntilsave()promotes the draft in one step and stamps a freshdecidedAt. AnysetRoutethat does not land on"preferences"discards the draft, so Back genuinely abandons unsaved edits. The tanstack/wasp blog posts already described exactly this draft model — the implementation now matches them.Changes
draftfield onConsentState;toggle()stages into it (no live commit, no persist, nosourceflip);save()promotesdraft ?? decisions;acceptAll/acceptNecessary/rejectand reprompt invalidation clear it; route changes discard it unless landing on"preferences"(banner → customise carries staged ticks forward).toggle(key)no longer takesActionOptions— nothing is recorded at toggle time, so the record source is named atsave(). (Previouslysave()overwrote toggle's source anyway, so no behavior is lost.)grantedaccessors readdraft ?? decisionsso checkboxes respond instantly pre-save; bindings that mirrorConsentStateexposedraftfor custom panels.has()reflecting unsaved toggles, persist-on-toggle) and added coverage for gate-ignores-staged-toggles, no-write-before-save for returning visitors (freshdecidedAton the saved record), draft discard on Back, draft carry-over banner → preferences, and reprompt clearing the draft.Reviewer notes
useCategory().grantedintentionally reads the draft (the checkbox view) whilehas()/ConsentGateintentionally do not (effective consent) — that split is the fix.decisionsmust switch todraft ?? decisions; the per-category accessors do it already.setRoute— rewrites the record with the normalized locale. Pre-existing, orthogonal to this fix.vp run -r test(all 11 workspaces),vp check, andvp run -r check-types.