Apply the saved review-card fill before paint so reload does not flash the teal placeholder.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
adilalloandCursor committed 2026-09-29 14:48:19 -06:00
1 parent b12de611f7
commit 782b1e1d64
2 files changed
+22 -14

No files matched your search

@@ -1,19 +1,21 @@
"use client"; "use client";
import { useEffect, useState } from "react"; import { useEffect, useLayoutEffect, useState } from "react";
import { dominantColorFromImageUrl } from "../../../../lib/create/previewSurfaceColor"; import {
dominantColorFromImageUrl,
isPreviewSurfaceColor,
} from "../../../../lib/create/previewSurfaceColor";
import { resolvePreviewSurfaceFallback } from "../utils/resolvePreviewSurfaceFallback"; import { resolvePreviewSurfaceFallback } from "../utils/resolvePreviewSurfaceFallback";
/** /**
* Fill for the review preview card. An uploaded logo contributes its most * Fill for the review preview card. An uploaded logo contributes its most
* common color; no image uses a random light color stored on the draft so * common color; no image uses a random light color stored on the draft so
* reload keeps the same fill. Unset until mount so the server and client * reload keeps the same fill.
* share the fallback class.
* *
* @param imageUrl Uploaded logo URL, or `null` when the user skipped the photo. * @param imageUrl Uploaded logo URL, or `null` when the user skipped the photo.
* @param storedFallback Draft `previewSurfaceColor`, if already picked. * @param storedFallback Draft `previewSurfaceColor`, if already picked.
* @param persistFallback Writes the fallback onto React state once. * @param persistFallback Writes the fallback onto React state once.
* @returns A CSS color, or `undefined` before the client picks one. * @returns A CSS color, or `undefined` before the client resolves one.
* *
* @example * @example
* const color = usePreviewSurfaceColor(avatarUrl, state.previewSurfaceColor, persist); * const color = usePreviewSurfaceColor(avatarUrl, state.previewSurfaceColor, persist);
@@ -23,16 +25,22 @@ export function usePreviewSurfaceColor(
storedFallback: string | undefined, storedFallback: string | undefined,
persistFallback: (_color: string) => void, persistFallback: (_color: string) => void,
): string | undefined { ): string | undefined {
const [color, setColor] = useState<string | undefined>(undefined); const [color, setColor] = useState<string | undefined>(() =>
storedFallback && isPreviewSurfaceColor(storedFallback)
? storedFallback
: undefined,
);
useEffect(() => { useLayoutEffect(() => {
if (!imageUrl) { if (imageUrl) return;
const next = resolvePreviewSurfaceFallback(storedFallback); const next = resolvePreviewSurfaceFallback(storedFallback);
persistFallback(next); persistFallback(next);
// eslint-disable-next-line react-hooks/set-state-in-effect -- random fill is client-only; first paint stays on the fallback class // eslint-disable-next-line react-hooks/set-state-in-effect -- apply before paint so reload does not flash the teal token
setColor(next); setColor((prev) => (prev === next ? prev : next));
return; }, [imageUrl, persistFallback, storedFallback]);
}
useEffect(() => {
if (!imageUrl) return;
let cancelled = false; let cancelled = false;
void dominantColorFromImageUrl(imageUrl).then((extracted) => { void dominantColorFromImageUrl(imageUrl).then((extracted) => {
@@ -311,12 +311,12 @@ export function FinalReviewScreen({
size={mdUp ? "L" : "M"} size={mdUp ? "L" : "M"}
expanded={true} expanded={true}
descriptionAtBottom descriptionAtBottom
backgroundColor="bg-[var(--color-surface-invert-brand-teal)]" backgroundColor="bg-transparent"
surfaceColor={surfaceColor} surfaceColor={surfaceColor}
logoUrl={avatarUrl ?? getAssetPath(vectorMarkPath("mutual-aid"))} logoUrl={avatarUrl ?? getAssetPath(vectorMarkPath("mutual-aid"))}
logoAlt={ruleCardTitle} logoAlt={ruleCardTitle}
categories={finalReviewCategories} categories={finalReviewCategories}
className={CREATE_FLOW_REVIEW_RULE_LAYOUT_CLASS} className={`${CREATE_FLOW_REVIEW_RULE_LAYOUT_CLASS}${surfaceColor ? "" : " invisible"}`}
onClick={() => {}} onClick={() => {}}
/> />
<FinalReviewChipEditModal <FinalReviewChipEditModal