@snowcone-app/ui 0.11.6 → 0.11.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowcone-app/ui",
3
- "version": "0.11.6",
3
+ "version": "0.11.9",
4
4
  "description": "React components for merchandise visualization and customization",
5
5
  "keywords": [
6
6
  "react",
@@ -103,7 +103,7 @@
103
103
  "react-instantsearch": "^7.15.5",
104
104
  "react-zoom-pan-pinch": "^3.6.4",
105
105
  "tailwind-merge": "^3.0.0",
106
- "@snowcone-app/sdk": "0.31.12"
106
+ "@snowcone-app/sdk": "0.31.14"
107
107
  },
108
108
  "devDependencies": {
109
109
  "@chromatic-com/storybook": "^4.1.2",
@@ -180,6 +180,21 @@ export interface HeroProductImageProps {
180
180
  * // Without realtime (static mockups):
181
181
  * <HeroProductImage placement="Front" mockupId="..." artwork={artwork} />
182
182
  */
183
+ /**
184
+ * The session error that can refuse a picture. A retryable one (busy / slow render server: E_RT_RENDER_BUSY,
185
+ * E_RT_PREVIEW_SLOW) is "behind", not a refusal: the picture reads 'stale' until it catches up
186
+ * (#6140: after #6137 a slow box stamped every behind picture 'refused').
187
+ */
188
+ export function blockingSessionError(error: { code: string; retryable?: boolean } | null | undefined): string | null {
189
+ return error && !error.retryable ? error.code : null;
190
+ }
191
+
192
+ /** data-render-state for a live picture: refused (a typed refusal, or behind under a blocking error) > stale > current. */
193
+ export function pictureRenderState(s: { refusal: string | null; sessionError: string | null; behind: boolean }): "refused" | "stale" | "current" {
194
+ if (s.refusal || (s.behind && s.sessionError)) return "refused";
195
+ return s.behind ? "stale" : "current";
196
+ }
197
+
183
198
  export const HeroProductImage = memo(function HeroProductImage({
184
199
  productId,
185
200
  mockupId,
@@ -595,7 +610,7 @@ export const HeroProductImage = memo(function HeroProductImage({
595
610
  const frameFailedRef = useRef(realtimeContext?.frameFailed);
596
611
  frameFailedRef.current = realtimeContext?.frameFailed;
597
612
  const sessionErrorCodeRef = useRef<string | null>(null);
598
- sessionErrorCodeRef.current = realtimeContext?.renderError?.code ?? null;
613
+ sessionErrorCodeRef.current = blockingSessionError(realtimeContext?.renderError);
599
614
  const getCanvasVersion = realtimeContext?.getCanvasVersion;
600
615
  const getSessionShape = realtimeContext?.getSessionShape;
601
616
  const applyRenderStamp = useCallback(() => {
@@ -630,9 +645,7 @@ export const HeroProductImage = memo(function HeroProductImage({
630
645
  node.dataset.arrivedVersion = String(arrivedVersionRef.current);
631
646
  if (frameErrorRef.current) node.dataset.frameError = frameErrorRef.current;
632
647
  else delete node.dataset.frameError;
633
- node.dataset.renderState = refusalCodeRef.current || (behind && sessionErrorCodeRef.current)
634
- ? "refused"
635
- : behind ? "stale" : "current";
648
+ node.dataset.renderState = pictureRenderState({ refusal: refusalCodeRef.current, sessionError: sessionErrorCodeRef.current, behind });
636
649
  // Resolution: the width the shown image really has vs the width the
637
650
  // session wants now (an editing-width frame after Done is marked, not
638
651
  // passed off as the hero).
@@ -1354,13 +1367,19 @@ export const HeroProductImage = memo(function HeroProductImage({
1354
1367
  render (e.g. asset_not_allowed). The stale image above stays visible
1355
1368
  on purpose (stale + clearly marked beats blank); the typed code is
1356
1369
  exposed via data-render-error so agents/tests can assert on it. */}
1370
+ {/* A retryable error (busy / slow render server) is not a block: it says the preview is behind and catches up. */}
1357
1371
  {realtimeContext?.renderError && (
1358
1372
  <div
1359
- role="alert"
1373
+ role={realtimeContext.renderError.retryable ? "status" : "alert"}
1360
1374
  data-render-error={realtimeContext.renderError.code}
1361
- className="absolute inset-x-0 bottom-0 z-20 bg-red-600/90 text-white text-xs font-medium px-3 py-2 pointer-events-none"
1375
+ data-render-error-retryable={realtimeContext.renderError.retryable ? "true" : undefined}
1376
+ className={`absolute inset-x-0 bottom-0 z-20 text-xs font-medium px-3 py-2 pointer-events-none ${
1377
+ realtimeContext.renderError.retryable ? "bg-amber-500/90 text-black" : "bg-red-600/90 text-white"
1378
+ }`}
1362
1379
  >
1363
- {`Render blocked: ${realtimeContext.renderError.code} — ${realtimeContext.renderError.message}`}
1380
+ {realtimeContext.renderError.retryable
1381
+ ? realtimeContext.renderError.message
1382
+ : `Render blocked: ${realtimeContext.renderError.code} — ${realtimeContext.renderError.message}`}
1364
1383
  </div>
1365
1384
  )}
1366
1385
 
@@ -0,0 +1,31 @@
1
+ /**
2
+ * #6140: a slow render server raises a retryable E_RT_PREVIEW_SLOW (#6137). That is "behind", never "refused":
3
+ * the canary and agents read data-render-state, and a slow box stamped 'refused' alarmed E_CANARY_REFUSED.
4
+ */
5
+ import { describe, expect, it } from "vitest";
6
+ import { blockingSessionError, pictureRenderState } from "../HeroProductImage";
7
+
8
+ describe("HeroProductImage render state", () => {
9
+ it("a retryable session error (slow / busy server) leaves a behind picture 'stale'", () => {
10
+ const sessionError = blockingSessionError({ code: "E_RT_PREVIEW_SLOW", retryable: true });
11
+ expect(sessionError).toBeNull();
12
+ expect(pictureRenderState({ refusal: null, sessionError, behind: true })).toBe("stale");
13
+ });
14
+
15
+ it("a blocking session error on a behind picture is 'refused'", () => {
16
+ const sessionError = blockingSessionError({ code: "E_MOCKUP_UNRENDERABLE" });
17
+ expect(sessionError).toBe("E_MOCKUP_UNRENDERABLE");
18
+ expect(pictureRenderState({ refusal: null, sessionError, behind: true })).toBe("refused");
19
+ expect(pictureRenderState({ refusal: null, sessionError, behind: false })).toBe("current");
20
+ });
21
+
22
+ it("a typed refusal is 'refused' whatever the version", () => {
23
+ expect(pictureRenderState({ refusal: "asset_not_allowed", sessionError: null, behind: false })).toBe("refused");
24
+ });
25
+
26
+ it("no error: behind is 'stale', caught up is 'current'", () => {
27
+ expect(blockingSessionError(null)).toBeNull();
28
+ expect(pictureRenderState({ refusal: null, sessionError: null, behind: true })).toBe("stale");
29
+ expect(pictureRenderState({ refusal: null, sessionError: null, behind: false })).toBe("current");
30
+ });
31
+ });