-
Notifications
You must be signed in to change notification settings - Fork 6
refactor(cards): simplify placeholder text + drive loading state from Realtime #951
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2deb0c4
feat(cards): collapse bookmark image placeholder text to two states
rogerantony-dev 94b437c
refactor(realtime): drive card loading state from subscription manager
rogerantony-dev e4d16ff
Merge branch 'dev' into feat/simplify-card-loading-states
rogerantony-dev c487170
Merge dev into feat/simplify-card-loading-states
rogerantony-dev 583172d
fix(realtime): notify listeners on waiting-queue teardown paths
rogerantony-dev b91fe4c
fix(add-bookmark): guarantee subscription teardown on pipeline throw
rogerantony-dev 86468c2
fix(cards): run placeholder exit animation when statusText clears
rogerantony-dev 958ee45
fix(realtime): declare meta_data.mediaType in schema
rogerantony-dev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { useCallback, useSyncExternalStore } from "react"; | ||
|
|
||
| import { | ||
| isBookmarkEnrichmentActive, | ||
| subscribeToBookmarkEnrichmentChanges, | ||
| } from "@/lib/supabase/realtime/bookmark-enrichment-subscription"; | ||
|
|
||
| /** | ||
| * Reactive read of the subscription manager's "is this bookmark still being | ||
| * enriched?" state. Used by the card placeholder to show a "Getting | ||
| * screenshot" label while the server pipeline (screenshot + AI enrichment or | ||
| * PDF thumbnail) is in flight. | ||
| * | ||
| * Returns `true` while a Realtime subscription is active or queued for the | ||
| * given bookmark id; `false` once the subscription tears down (terminal | ||
| * state, timeout, delete, sign-out, or explicit teardown on non-enriching | ||
| * media paths). | ||
| */ | ||
| export function useBookmarkEnrichmentActive(bookmarkId: number): boolean { | ||
| const getSnapshot = useCallback(() => isBookmarkEnrichmentActive(bookmarkId), [bookmarkId]); | ||
| return useSyncExternalStore(subscribeToBookmarkEnrichmentChanges, getSnapshot, getSnapshot); | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did we removed this @rogerantony-dev ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The synchronous
setQueryData+removeLoadingBookmarkIdblock you added in 047d1b7 existed to paper over the race between the cache notify and the Zustand loading flag — landing them in two separate renders meant the card briefly saw(img=null, isLoading=false)and flashed theCannot fetch image...terminal of the 4-statestatusTextladder.Both legs of that race are gone in this PR:
animatedBookmarkImage.tsxnow rendersGetting screenshotwhile loading andnullotherwise — there is noCannot fetch imageterminal branch to flash through, so the mid-render gap is visually inert even if it happened.useBookmarkEnrichmentActive(id)off the subscription manager (useSyncExternalStore). The subscription stays active until the Realtime terminal condition fires (meta_data.screenshot+ogImageboth set, or PDF thumbnail write for PDFs). The screenshot mutation returning is not what flipsisLoadingtofalseanymore — the Realtime UPDATE is, and it carries the image with it.applyBookmarkUpdatesplices the row across every matching paginated / search / alt-category cache. ThesetQueryDatainonSettledwould re-do the same merge a few ms later.So the synchronous injection became redundant once (1) the ladder only has
loading/done, (2) loading comes from the subscription, not the mutation's return, and (3) the Realtime splice is the authoritative client-side cache write. TheinvalidateQueriesis kept purely as a safety net for the downstreamaddRemainingBookmarkDataenrichments (img_caption, OCR, blurhash, extra covers) that aren't on the Realtime publication.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ji since we are removing zustand state for loading completely, this fix is no longer needed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it