Skip to content

Fix bad save deck state caching on detail pages - #2338

Merged
jacbn merged 6 commits into
mainfrom
hotfix/book-page-save-deck
Sep 4, 2026
Merged

Fix bad save deck state caching on detail pages#2338
jacbn merged 6 commits into
mainfrom
hotfix/book-page-save-deck

Conversation

@jacbn

@jacbn jacbn commented Sep 1, 2026

Copy link
Copy Markdown
Contributor

Uses correct rtkq caching tags in book detail and revision detail pages. Paired with the API etag PR, this fixes issues with not appearing to save / unsave decks on these pages.

@codecov

codecov Bot commented Sep 1, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 22.22222% with 14 lines in your changes missing coverage. Please review.
✅ Project coverage is 43.56%. Comparing base (91eb3e9) to head (d33481c).
⚠️ Report is 72 commits behind head on main.

Files with missing lines Patch % Lines
src/app/components/pages/SubjectOverviewPage.tsx 50.00% 4 Missing ⚠️
src/app/state/slices/api/booksApi.ts 0.00% 4 Missing ⚠️
src/app/components/pages/RevisionDetailPage.tsx 0.00% 3 Missing ⚠️
src/app/state/slices/api/revisionApi.ts 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2338      +/-   ##
==========================================
- Coverage   43.57%   43.56%   -0.01%     
==========================================
  Files         601      601              
  Lines       25812    25827      +15     
  Branches     8590     7677     -913     
==========================================
+ Hits        11248    11252       +4     
- Misses      14515    14526      +11     
  Partials       49       49              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sjd210 sjd210 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.

I do need to read up more on RTKQ, but this much makes sense to me and definitely seems to work.

I noticed that subject overview pages were also not showing saved status. This was a slightly different issue (us not loading the gameboards at all), but for the sake of practice I've fixed it myself and committed that. I'd appreciate you having a look in counter-review.

@jacbn jacbn left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The query is great, just a little point about after it!

return items[subject].length > 0 ? <ListView className={className} type="gameboard" items={items[subject].map(convertToALVIGameboard)} /> : null;
const gameboardByIdQuery = useGetGameboardByIdQuery(gameboard_ids[subject]);

return gameboard_ids[subject]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This works great! maintainOnRefetch is proving its value :) probably my favourite addition to the codebase...

The only thing I'd say is that it feels odd to have a query that relies on gameboard_ids[subject] being defined, then afterwards have a conditional where we don't render contents if it is undefined. The query is still being executed and can still error prior.

There are really 3 solutions here, really up to you which you prefer:

  1. Have faith in TS type-checking; subject must be a valid key of gameboard_ids by its type definition. You don't really need the conditional here.

  2. If we are going to deal with the case where gameboard_ids[subject] can be undefined, we'll want to make the query parameter deal with this too so it can't error prior; skipTokens are our most common way.

    // skipToken needs importing
    const gameboardByIdQuery = useGetGameboardByIdQuery(gameboard_ids[subject] ?? skipToken);

    return gameboard_ids[subject] ? ...
  1. As an extension to 2, if you'd rather not have two conditionals with the same condition, you can make more extensive use of the tools inside ShowLoadingQuery with uninitializedPlaceholder; note though that there isn't a way to automatically reuse the error message, mainly because it being uninitialised isn't always an error state.
    const gameboardByIdQuery = useGetGameboardByIdQuery(gameboard_ids[subject] ?? skipToken);

    return <ShowLoadingQuery
        ...
        uninitializedPlaceholder={<>...</>}
    />;

@sjd210 sjd210 Sep 3, 2026

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.

Hrmm well looking in comparison to the book/revision detail pages, they fail a lot more gracefully by just not showing the gameboards section at all if they aren't loaded. For those pages and this one, the page as a whole is still functional without that section (unlike e.g. My Assignments where the page is fully broken so there really should be an error), so this feels sensible to me rather than alarming the user with a warning they don't really need to worry about.

It seems like a combination of uninitializedPlaceholder={RenderNothing} and adding ifNotFound={RenderNothing} handles this case best, so I'll go with that

@jacbn

jacbn commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

LGTM

@jacbn
jacbn merged commit 2ec91a1 into main Sep 4, 2026
10 checks passed
@jacbn
jacbn deleted the hotfix/book-page-save-deck branch September 4, 2026 08:50
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