Repository navigation
refactor(web): move Home Screen saves into one hook - #1901
Conversation
Settings > Home Screen fired a full override PUT on every change without waiting for the one before, so two quick edits could land out of order, and a merged save could only name one changed row, dropping a change to a legacy Trakt row with no saved override. useProfileHomeRows now owns the page's reads and writes: one save in flight, later changes merged into a single next save that carries every row they touched, the page switch refused until saves and their refetch land, and the last saved state put back when the newest save fails. The page's JSX is unchanged; its pure helpers move to lib/homeRows/profileOverrides.ts and are re-exported. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
…ring saves The save hook refuses a page switch while a save or its refetch is in flight, but the picker stayed enabled and snapped back with no feedback; it is now disabled while saves are pending, as the plan specifies. A reset also turned off editing, which the page reported as "Loading saved section state"; the hook now exposes `ready` apart from `canEdit` so the note shows only while the page is actually loading. A page render test covers a toggle, a delete and a reset going through the hook. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6ae0385f97
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| type QueueEntry = | ||
| | { kind: "save"; page: PageRef; state: PageState; changedIds: Set<string> } | ||
| | { kind: "reset"; page: PageRef }; |
There was a problem hiding this comment.
Bind queued writes to the originating profile
Capture the profile request context when each queue entry is created. If a user queues another save or reset behind an in-flight PUT and then switches household profiles, the delayed send() runs after the switch and the request helper uses the newly active profile because QueueEntry retains no authority snapshot. Clearing the query client does not cancel this local queue, so the old profile's layout can be written to—or reset on—the newly selected profile.
AGENTS.md reference: AGENTS.md:L105-L107
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 760e202. Each queued save or reset now captures the profile request context when it is queued, is sent with that profileContext, and is dropped if another profile is active by the time it would go out (its cached overrides would belong to the other profile). New hook test: a save queued behind an in-flight one is not sent after a profile switch, and the in-flight one goes out as the original profile.
| const changedIds = new Set(q.next?.kind === "save" ? q.next.changedIds : []); | ||
| changedIds.add(id); | ||
| q.next = { kind: "save", page, state: next, changedIds }; |
There was a problem hiding this comment.
Retain in-flight IDs in the successor save
When the first save is already in flight, q.next is null, so a later edit starts changedIds from an empty set instead of inheriting the running entry's IDs. If the first edit targets a shown, unsaved legacy Trakt row and that request fails while another row edit is queued, the successor state still contains the Trakt edit, but buildSectionOverrides treats that row as unchanged and omits it; the second PUT then succeeds without the earlier edit even though the hook promises that the newest state wins. Carry the running entry's changed IDs forward until its save succeeds.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Fixed in 760e202. When a save fails and a newer save is queued, the failed save's changed row IDs are added to the queued one, so a legacy Trakt row edited in the failed save is still named and written. Only the failure path carries them: after a successful save the refetched overrides already hold that row. New hook test covers the Trakt edit failing with another change queued behind it.
|
Major change — #1142 C2 (Web). Reordering now goes through the new The current Suggested fix: No diff; update the PR description to: Automated check: Macroscope check run agent (gpt-6-luna). No validation was performed. Posted via Macroscope — v1 validation impact |
…-title' into refactor/home-screen-save-hook
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6339ade6d2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| } else { | ||
| toast.error(sectionSaveErrorMessage(error)); | ||
| // A newer change still to be sent carries the user's latest state; keep it. | ||
| if (!q.next) setDraft(null); |
There was a problem hiding this comment.
Keep the failed draft until the refetch finishes
When a PUT fails with no already-queued successor, this clears draft before the awaited invalidation, while canEdit remains true during that background refetch because the queries still hold successful data. If the response was lost after the server committed the PUT and the user edits another row before the GET completes, that edit captures the stale pre-PUT serverSections; its subsequent full-replacement PUT then undoes the first change even after the refetch discovers it. Retain the draft or disable edits until the authoritative refetch has completed.
Useful? React with 👍 / 👎.
A save queued behind an in-flight one was sent with whatever household profile was active when it ran, so switching profiles mid-save could write or reset the old profile's layout on the new one. Each queued save now carries the profile it was made under, is sent with that authority, and is dropped if another profile is picked before it goes out. A failed save also no longer loses its rows from the save queued behind it: their IDs carry into that save, so an edit to a legacy Trakt row with no saved override is still written. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
Updated the PR body: the validation line now reads |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 760e2023a8
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| const base = draftRef.current ?? { | ||
| sections: serverSections ?? [], | ||
| removed: hydrateRemovedSystemSections(savedOverrides), | ||
| }; |
There was a problem hiding this comment.
Clear the old profile draft before accepting new edits
If profile A has a PUT in flight and the user switches to profile B, clearing the query cache can let B's queries become ready before A's request finishes; editing is not blocked by pending, so B's next change uses A's still-populated draftRef as its base. That entry captures B's authority and therefore passes the active-authority check, causing A's unsaved layout state to be included in the PUT for B. The fresh evidence beyond the earlier queued-authority report is that the newly queued entry belongs to B—the stale state enters through draftRef, so the new profile snapshot does not prevent the cross-profile write. Clear or partition the draft when profile authority changes, or keep editing disabled until the prior profile's drain completes.
AGENTS.md reference: AGENTS.md:L105-L107
Useful? React with 👍 / 👎.
| const changedIds = new Set(q.next?.kind === "save" ? q.next.changedIds : []); | ||
| changedIds.add(id); | ||
| q.next = { kind: "save", page, profile, state: next, changedIds }; |
There was a problem hiding this comment.
Retain running IDs until the raw override refetch succeeds
When a successful in-flight save is followed by a failed raw-overrides refetch while a successor save is queued, the successor's changedIds excludes the running entry's IDs and getQueryData still returns the pre-save overrides. If the first edit was to a shown legacy Trakt row without an old override, buildSectionOverrides consequently omits that row from the successor's full-replacement PUT and erases the edit that just succeeded. Fresh evidence beyond the earlier failure-path report is that this occurs after a successful PUT when only the raw-overrides GET fails, so the catch-path union added for failed PUTs never runs.
Useful? React with 👍 / 👎.
…factor/home-screen-save-hook
Problem
Related issue: #1137
Validation tasks: changes #1142 C2
#1142 C2 (reorder, reload, switch profiles and back) now runs through the new save queue instead of the page's separate PUT calls, so it needs a re-test after merge. The order should still persist: a single reorder sends the same payload as before, and a reorder made during another save is sent after it, so the newest order is the one that stays saved. Each queued save is now sent as the profile that made it, which keeps the profile switch in C2 from carrying a pending save onto the other profile. C2 has no passed result yet.
Stacked on #1900, which is stacked on #1898. Merge those first; this PR targets #1900's branch. Its own changes are web-only and do not read the field #1900 adds.
Settings > Home Screen can save a profile's rows out of order. Every toggle, drag, add, edit or delete sends
PUT /api/v2/profile/sectionswith the page's whole override set, and the page sends each one without waiting for the one before. The route checks no version, so when two quick changes land in the wrong order, the older state is what stays saved.This PR moves the page's reads and saves into one hook,
useProfileHomeRows. It sends one save at a time. Changes made while a save is in flight merge into a single next save, and the newest state wins. The Home rows redesign builds the new Settings > Home Screen on this hook, so the save rules get tested here, separately from the UI change.Approach
buildSectionOverridesnow acceptschangedSectionIds. The singlechangedSectionIdstill works and gives the same output. What a save stores is unchanged. Storing only the fields a profile changed is planned for the next PR, which replaces this page's UI.web/src/lib/homeRows/profileOverrides.ts. The page re-exports them, soHomeScreenSettings.test.tsxand the payload golden tests run unedited. Two of those helpers,shouldRestoreSelectionStateandshouldRestoreLatestSaveFailure, are now used only by that test file. They will be removed together with their tests when the page is rebuilt.useSaveProfileOverridesanduseResetProfileOverridesbecome plain request functions, because the hook has to await the refetch itself. Only this page used them.Validation
renderHookagainst a mocked v2 server) cover save ordering, merging, a merged change to a legacy Trakt row reaching the PUT, page-switch refusal, rollback after a failure, a stale failure not undoing a newer save, a failed save's Trakt row edit reaching the save queued behind it, a queued save being dropped after a profile switch,pendinglasting until the refetch, no writes before the overrides load, and a reset waiting behind an in-flight save. Breaking the changed-id union, the rollback condition or the one-at-a-time guard makes them fail.buildSectionOverridesunit tests cover several changed ids and confirm a one-id set matcheschangedSectionId.HomeScreenSettings.test.tsxis unedited and passes.format:check,tsc -b, build,budget:checkandmake test-web: pass.make verify-local-paths: pass.Risks
Checklist
AI Disclosure
tsc -b. It approved with three minor findings, all fixed in the second commit. First, a reset showed "Loading saved section state"; the hook now reports readiness separately from editability. Second, a page switch during a save snapped back silently; the picker is now disabled. Third, the page had no render test; one was added. Two nits were not fixed. The failed-refetch case is recorded under Risks. The two helpers with no production callers stay until the unedited test file that imports them is replaced.🤖 Generated with Claude Code
Note
Move Home Screen section saves into
useProfileHomeRowshookuseProfileHomeRowshook that holds home-screen edits as local drafts and sends saves one operation at a time (useProfileHomeRows.ts).HomeScreenSettingsinto a reusable module and letsbuildSectionOverridesaccept a set of changed section IDs, so legacy Trakt rows changed in a merged save are no longer dropped (profileOverrides.ts).HomeScreenSettingsto delegate queries, drafts, saves, resets, and scope handling to the hook; the scope picker is disabled while work is pending (HomeScreenSettings.tsx).replaceProfileSectionOverridesandresetProfileSectionOverridesin sections.ts no longer invalidate queries themselves; invalidation now happens only in the hook, so any other callers of these functions lose automatic cache refresh. Editing is also blocked until both section queries load, and page changes are refused while saves or resets drain.Macroscope summarized 99bb457.