@charcuterie/ui 4.28.2 → 4.28.4

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.
Files changed (38) hide show
  1. package/dist/Avatar/Avatar.d.ts.map +1 -1
  2. package/dist/Avatar/Avatar.js +6 -15
  3. package/dist/Avatar/Avatar.js.map +1 -1
  4. package/dist/PortraitTiles/PortraitAvatar.d.ts +5 -0
  5. package/dist/PortraitTiles/PortraitAvatar.d.ts.map +1 -1
  6. package/dist/PortraitTiles/PortraitAvatar.js +9 -6
  7. package/dist/PortraitTiles/PortraitAvatar.js.map +1 -1
  8. package/dist/markdownEditorCodeMirror/finishParsing.testHelpers.d.ts +29 -0
  9. package/dist/markdownEditorCodeMirror/finishParsing.testHelpers.d.ts.map +1 -0
  10. package/dist/markdownEditorCodeMirror/finishParsing.testHelpers.js +38 -0
  11. package/dist/markdownEditorCodeMirror/finishParsing.testHelpers.js.map +1 -0
  12. package/dist/motion.testHelpers.d.ts +35 -0
  13. package/dist/motion.testHelpers.d.ts.map +1 -0
  14. package/dist/motion.testHelpers.js +44 -0
  15. package/dist/motion.testHelpers.js.map +1 -0
  16. package/dist/useImageFailure.d.ts +52 -0
  17. package/dist/useImageFailure.d.ts.map +1 -0
  18. package/dist/useImageFailure.js +71 -0
  19. package/dist/useImageFailure.js.map +1 -0
  20. package/dist/waitForImages.testHelpers.d.ts +33 -0
  21. package/dist/waitForImages.testHelpers.d.ts.map +1 -0
  22. package/dist/waitForImages.testHelpers.js +48 -0
  23. package/dist/waitForImages.testHelpers.js.map +1 -0
  24. package/package.json +3 -3
  25. package/src/Avatar/Avatar.test.tsx +54 -1
  26. package/src/Avatar/Avatar.tsx +7 -19
  27. package/src/GroupedList/GroupedList.test.tsx +22 -17
  28. package/src/Motion/useListMotion.test.tsx +21 -15
  29. package/src/Motion/usePresence.test.tsx +76 -24
  30. package/src/Motion/useValueChangeMotion.test.tsx +12 -9
  31. package/src/Overlay/overlayReturnFocus.test.tsx +18 -20
  32. package/src/PortraitTiles/PortraitAvatar.tsx +10 -5
  33. package/src/PortraitTiles/PortraitTiles.test.tsx +219 -17
  34. package/src/markdownEditorCodeMirror/MarkdownView.test.tsx +32 -11
  35. package/src/markdownEditorCodeMirror/finishParsing.testHelpers.ts +47 -0
  36. package/src/motion.testHelpers.ts +46 -0
  37. package/src/useImageFailure.ts +93 -0
  38. package/src/waitForImages.testHelpers.ts +61 -0
@@ -1 +1 @@
1
- {"version":3,"file":"Avatar.d.ts","sourceRoot":"","sources":["../../src/Avatar/Avatar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAE3D,OAAO,KAAK,EACV,qBAAqB,EACrB,SAAS,EACV,MAAM,OAAO,CAAA;AAId,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAG1D,MAAM,MAAM,UAAU,GAAG,MAAM,OAAO,iBAAiB,CAAA;AAEvD,MAAM,MAAM,WAAW,GAAG,IAAI,CAC5B,qBAAqB,CAAC,MAAM,CAAC,EAC7B,UAAU,CACX,GAAG;IACF;;;;;OAKG;IACH,UAAU,CAAC,EAAE,OAAO,CAAC,gBAAgB,EAAE,OAAO,CAAC,CAAA;IAC/C;;;;OAIG;IACH,WAAW,CAAC,EAAE,gBAAgB,CAAA;IAC9B;;;;;;;;OAQG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;;;;;;;OAQG;IACH,IAAI,CAAC,EAAE,SAAS,CAAA;IAChB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;;;;;OAQG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB;;;;;;;OAOG;IACH,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAC/B,IAAI,CAAC,EAAE,UAAU,CAAA;CAClB,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,Q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;;;;;;;;;;;;;;;GA8DG;AACH,eAAO,MAAM,MAAM,GAAI,mHAYpB,WAAW,KAAG,SAsDhB,CAAA"}
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { getCategoricalIndex } from "@charcuterie/tokens";
3
- import { useState } from "react";
4
3
  import { CATEGORICAL_APPEARANCE_CLASS } from "../categoricalStyles.js";
5
4
  import { toClassName } from "../toClassName.js";
5
+ import { useImageFailure } from "../useImageFailure.js";
6
6
  /**
7
7
  * One rule: **the circle is 1.9 x its own type size**, and `size`
8
8
  * picks which step of the type scale that is.
@@ -113,18 +113,11 @@ const toInitials = (name) => name
113
113
  */
114
114
  export const Avatar = ({ appearance = "soft", categorical, categoricalKey, className, icon, imageUrl, initials, name, size = "md", title, ...spanProps }) => {
115
115
  /**
116
- * The URL that failed, rather than a `hasFailed` boolean.
117
- *
118
- * A boolean has to be *reset* when `imageUrl` changes, which is an
119
- * effect syncing a prop into state — the shape this library
120
- * refuses everywhere else
121
- * ([decision](../../../docs/decisions/2026-07-29-logic-hooks-are-uncontrolled.md)).
122
- * Storing the URL makes the comparison below derive the answer, so
123
- * a second photo gets its own attempt and a re-render never
124
- * resurrects a dead one.
116
+ * Keyed by the URL that failed, so a second photo gets its own
117
+ * attempt, and it also notices a photo that failed before a
118
+ * server render hydrated — see `useImageFailure`.
125
119
  */
126
- const [failedImageUrl, setFailedImageUrl] = useState(undefined);
127
- const hasImageError = imageUrl !== undefined && failedImageUrl === imageUrl;
120
+ const { hasFailed: hasImageError, imageProps } = useImageFailure(imageUrl);
128
121
  const trimmedName = name?.trim();
129
122
  if (!trimmedName) {
130
123
  return null;
@@ -132,8 +125,6 @@ export const Avatar = ({ appearance = "soft", categorical, categoricalKey, class
132
125
  const resolvedInitials = initials ?? toInitials(trimmedName);
133
126
  const resolvedCategorical = categorical ??
134
127
  getCategoricalIndex(categoricalKey ?? trimmedName);
135
- return (_jsx("span", { ...spanProps, "aria-label": trimmedName, className: toClassName("inline-grid shrink-0 place-items-center overflow-hidden rounded-full border font-medium leading-none", AVATAR_SIZE_CLASS[size], CATEGORICAL_APPEARANCE_CLASS[resolvedCategorical][appearance], className), role: "img", title: title ?? trimmedName, children: imageUrl !== undefined && !hasImageError ? (_jsx("img", { alt: "", className: "size-full object-cover", onError: () => {
136
- setFailedImageUrl(imageUrl);
137
- }, src: imageUrl })) : (_jsx("span", { "aria-hidden": "true", children: icon ?? resolvedInitials })) }));
128
+ return (_jsx("span", { ...spanProps, "aria-label": trimmedName, className: toClassName("inline-grid shrink-0 place-items-center overflow-hidden rounded-full border font-medium leading-none", AVATAR_SIZE_CLASS[size], CATEGORICAL_APPEARANCE_CLASS[resolvedCategorical][appearance], className), role: "img", title: title ?? trimmedName, children: imageUrl !== undefined && !hasImageError ? (_jsx("img", { ...imageProps, alt: "", className: "size-full object-cover", src: imageUrl })) : (_jsx("span", { "aria-hidden": "true", children: icon ?? resolvedInitials })) }));
138
129
  };
139
130
  //# sourceMappingURL=Avatar.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Avatar.js","sourceRoot":"","sources":["../../src/Avatar/Avatar.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAKzD,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC,OAAO,EAAE,4BAA4B,EAAE,MAAM,yBAAyB,CAAA;AAEtE,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAsE/C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,iBAAiB,GAAG;IACxB,EAAE,EAAE,sBAAsB;IAC1B,EAAE,EAAE,sBAAsB;IAC1B,EAAE,EAAE,sBAAsB;CAClB,CAAA;AAEV;;;;;;GAMG;AACH,MAAM,UAAU,GAAG,CAAC,IAAY,EAAU,EAAE,CAC1C,IAAI;KACD,IAAI,EAAE;KACN,KAAK,CAAC,KAAK,CAAC;KACZ,KAAK,C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,EACrB,UAAU,GAAG,MAAM,EACnB,WAAW,EACX,cAAc,EACd,SAAS,EACT,IAAI,EACJ,QAAQ,EACR,QAAQ,EACR,IAAI,EACJ,IAAI,GAAG,IAAI,EACX,KAAK,EACL,GAAG,SAAS,EACA,EAAa,EAAE;IAC3B;;;;OAIG;IACH,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,GAC5C,eAAe,CAAC,QAAQ,CAAC,CAAA;IAE3B,MAAM,WAAW,GAAG,IAAI,EAAE,IAAI,EAAE,CAAA;IAEhC,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,IAAI,CAAA;IACb,CAAC;IAED,MAAM,gBAAgB,GACpB,QAAQ,IAAI,UAAU,CAAC,WAAW,CAAC,CAAA;IAErC,MAAM,mBAAmB,GACvB,WAAW;QACX,mBAAmB,CAAC,cAAc,IAAI,WAAW,CAAC,CAAA;IAEpD,OAAO,CACL,kBACM,SAAS,gBACD,WAAW,EACvB,SAAS,EAAE,WAAW,CACpB,sGAAsG,EACtG,iBAAiB,CAAC,IAAI,CAAC,EACvB,4BAA4B,CAAC,mBAAmB,CAAC,CAC/C,UAAU,CACX,EACD,SAAS,CACV,EACD,IAAI,EAAC,KAAK,EACV,KAAK,EAAE,KAAK,IAAI,WAAW,YAE1B,QAAQ,KAAK,SAAS,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,CAI1C,iBACM,UAAU,EACd,GAAG,EAAC,EAAE,EACN,SAAS,EAAC,wBAAwB,EAClC,GAAG,EAAE,QAAQ,GACb,CACH,CAAC,CAAC,CAAC,CACF,8BAAkB,MAAM,YACrB,IAAI,IAAI,gBAAgB,GACpB,CACR,GACI,CACR,CAAA;AACH,CAAC,CAAA"}
@@ -9,6 +9,11 @@ import type { ReactNode } from "react";
9
9
  * network stripped — so the fallback the caller already supplied for
10
10
  * "no picture" covers "no picture *today*" as well.
11
11
  *
12
+ * The failure is keyed by URL, so a tile whose photo failed tries
13
+ * again when the caller passes a new one, and a photo that failed
14
+ * before a server render hydrated is noticed too — see
15
+ * `useImageFailure`.
16
+ *
12
17
  * Its own component because the state is per portrait. Hoisting it
13
18
  * to a `Record<string, boolean>` in the set would re-render every
14
19
  * tile whenever any one image failed.
@@ -1 +1 @@
1
- {"version":3,"file":"PortraitAvatar.d.ts","sourceRoot":"","sources":["../../src/PortraitTiles/PortraitAvatar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGtC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,cAAc,GAAI,oCAI5B;IACD,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,QAAQ,EAAE,SAAS,CAAA;CACpB,KAAG,SAuBH,CAAA"}
1
+ {"version":3,"file":"PortraitAvatar.d.ts","sourceRoot":"","sources":["../../src/PortraitTiles/PortraitAvatar.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAItC;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,cAAc,GAAI,oCAI5B;IACD,SAAS,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B,QAAQ,EAAE,SAAS,CAAA;CACpB,KAAG,SAsBH,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
- import { useState } from "react";
2
+ import { useImageFailure } from "../useImageFailure.js";
3
3
  /**
4
4
  * The face, and the one piece of this component that holds state.
5
5
  *
@@ -10,20 +10,23 @@ import { useState } from "react";
10
10
  * network stripped — so the fallback the caller already supplied for
11
11
  * "no picture" covers "no picture *today*" as well.
12
12
  *
13
+ * The failure is keyed by URL, so a tile whose photo failed tries
14
+ * again when the caller passes a new one, and a photo that failed
15
+ * before a server render hydrated is noticed too — see
16
+ * `useImageFailure`.
17
+ *
13
18
  * Its own component because the state is per portrait. Hoisting it
14
19
  * to a `Record<string, boolean>` in the set would re-render every
15
20
  * tile whenever any one image failed.
16
21
  */
17
22
  export const PortraitAvatar = ({ className, imageSrc, initials, }) => {
18
- const [isImageBroken, setIsImageBroken] = useState(false);
23
+ const { hasFailed: isImageBroken, imageProps } = useImageFailure(imageSrc);
19
24
  if (imageSrc === undefined || isImageBroken) {
20
25
  return (_jsx("span", { "aria-hidden": true, className: className, children: initials }));
21
26
  }
22
- return (_jsx("img", {
27
+ return (_jsx("img", { ...imageProps,
23
28
  // The name is beside it, inside the same tile, so an alt here
24
29
  // is the name announced twice.
25
- alt: "", className: className, onError: () => {
26
- setIsImageBroken(true);
27
- }, src: imageSrc }));
30
+ alt: "", className: className, src: imageSrc }));
28
31
  };
29
32
  //# sourceMappingURL=PortraitAvatar.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"PortraitAvatar.js","sourceRoot":"","sources":["../../src/PortraitTiles/PortraitAvatar.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAEhC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAC7B,SAAS,EACT,QAAQ,EACR,QAAQ,GAKT,EAAa,EAAE;IACd,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAA;IAEzD,IAAI,QAAQ,KAAK,SAAS,IAAI,aAAa,EAAE,CAAC;QAC5C,OAAO,CACL,oCAAkB,SAAS,EAAE,SAAS,YACnC,QAAQ,GACJ,CACR,CAAA;IACH,CAAC;IAED,OAAO,CACL;QACE,8DAA8D;QAC9D,+BAA+B;QAC/B,GAAG,EAAC,EAAE,EACN,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE,GAAG,EAAE;YACZ,gBAAgB,CAAC,IAAI,CAAC,CAAA;QACxB,CAAC,EACD,GAAG,EAAE,QAAQ,GACb,CACH,CAAA;AACH,CAAC,CAAA"}
1
+ {"version":3,"file":"PortraitAvatar.js","sourceRoot":"","sources":["../../src/PortraitTiles/PortraitAvatar.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAA;AAEvD;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,EAC7B,SAAS,EACT,QAAQ,EACR,QAAQ,GAKT,EAAa,EAAE;IACd,MAAM,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,GAC5C,eAAe,CAAC,QAAQ,CAAC,CAAA;IAE3B,IAAI,QAAQ,KAAK,SAAS,IAAI,aAAa,EAAE,CAAC;QAC5C,OAAO,CACL,oCAAkB,SAAS,EAAE,SAAS,YACnC,QAAQ,GACJ,CACR,CAAA;IACH,CAAC;IAED,OAAO,CACL,iBACM,UAAU;QACd,8DAA8D;QAC9D,+BAA+B;QAC/B,GAAG,EAAC,EAAE,EACN,SAAS,EAAE,SAAS,EACpB,GAAG,EAAE,QAAQ,GACb,CACH,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Parse every CodeMirror document under `root` to its end, now, so the
3
+ * decorations a test asserts on are drawn before it looks.
4
+ *
5
+ * This is the readiness signal for anything CodeMirror decorates — a
6
+ * heading, a link, a task box, a table. Those are drawn from the
7
+ * syntax tree, and CodeMirror does **not** finish that tree on mount.
8
+ * It parses for about 20 ms when the state is created, and hands the
9
+ * rest to a background worker that waits at least 100 ms, and up to
10
+ * 500 ms, between slices. On a quiet machine the first 20 ms covers a
11
+ * story's document. On a shared CI runner the same 20 ms of wall time
12
+ * covers less of it, the worker takes over, and a `findBy` with
13
+ * Testing Library's 1 s default is a race against that schedule.
14
+ * `MarkdownView > a checkbox is inert until a consumer says where the
15
+ * tick goes` lost that race in the narrow window on 2026-10-13; three
16
+ * other tests in the file had already been given a `findBy` or a
17
+ * `waitFor` for the same reason.
18
+ *
19
+ * `forceParsing` runs the same parser to the end of the document and
20
+ * dispatches the finished tree, so the component's own decoration
21
+ * passes run exactly as they would after the worker — only without
22
+ * the wait. It is not a fake: nothing in the component is stubbed.
23
+ *
24
+ * The budget is unbounded because a story's document is a few dozen
25
+ * lines; a parse that does not finish is a hang the test's own
26
+ * timeout reports.
27
+ */
28
+ export declare const finishCodeMirrorParsing: (root: ParentNode) => void;
29
+ //# sourceMappingURL=finishParsing.testHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"finishParsing.testHelpers.d.ts","sourceRoot":"","sources":["../../src/markdownEditorCodeMirror/finishParsing.testHelpers.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,uBAAuB,GAClC,MAAM,UAAU,KACf,IAcF,CAAA"}
@@ -0,0 +1,38 @@
1
+ import { forceParsing } from "@codemirror/language";
2
+ import { EditorView } from "@codemirror/view";
3
+ /**
4
+ * Parse every CodeMirror document under `root` to its end, now, so the
5
+ * decorations a test asserts on are drawn before it looks.
6
+ *
7
+ * This is the readiness signal for anything CodeMirror decorates — a
8
+ * heading, a link, a task box, a table. Those are drawn from the
9
+ * syntax tree, and CodeMirror does **not** finish that tree on mount.
10
+ * It parses for about 20 ms when the state is created, and hands the
11
+ * rest to a background worker that waits at least 100 ms, and up to
12
+ * 500 ms, between slices. On a quiet machine the first 20 ms covers a
13
+ * story's document. On a shared CI runner the same 20 ms of wall time
14
+ * covers less of it, the worker takes over, and a `findBy` with
15
+ * Testing Library's 1 s default is a race against that schedule.
16
+ * `MarkdownView > a checkbox is inert until a consumer says where the
17
+ * tick goes` lost that race in the narrow window on 2026-10-13; three
18
+ * other tests in the file had already been given a `findBy` or a
19
+ * `waitFor` for the same reason.
20
+ *
21
+ * `forceParsing` runs the same parser to the end of the document and
22
+ * dispatches the finished tree, so the component's own decoration
23
+ * passes run exactly as they would after the worker — only without
24
+ * the wait. It is not a fake: nothing in the component is stubbed.
25
+ *
26
+ * The budget is unbounded because a story's document is a few dozen
27
+ * lines; a parse that does not finish is a hang the test's own
28
+ * timeout reports.
29
+ */
30
+ export const finishCodeMirrorParsing = (root) => {
31
+ for (const element of root.querySelectorAll(".cm-editor")) {
32
+ const view = EditorView.findFromDOM(element);
33
+ if (view !== null) {
34
+ forceParsing(view, view.state.doc.length, Number.POSITIVE_INFINITY);
35
+ }
36
+ }
37
+ };
38
+ //# sourceMappingURL=finishParsing.testHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"finishParsing.testHelpers.js","sourceRoot":"","sources":["../../src/markdownEditorCodeMirror/finishParsing.testHelpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAAG,CACrC,IAAgB,EACV,EAAE;IACR,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,gBAAgB,CACzC,YAAY,CACb,EAAE,CAAC;QACF,MAAM,IAAI,GAAG,UAAU,CAAC,WAAW,CAAC,OAAO,CAAC,CAAA;QAE5C,IAAI,IAAI,KAAK,IAAI,EAAE,CAAC;YAClB,YAAY,CACV,IAAI,EACJ,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,EACrB,MAAM,CAAC,iBAAiB,CACzB,CAAA;QACH,CAAC;IACH,CAAC;AACH,CAAC,CAAA"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * A motion length no test outlives: an hour.
3
+ *
4
+ * The motion tests assert what is true **while** something moves — an
5
+ * item still entering, a row still leaving, a slide still in flight —
6
+ * right after a `userEvent` call. Each of those calls is a round trip
7
+ * to the browser driver, and on a shared CI runner one round trip has
8
+ * no upper bound. A 600 ms or 1 500 ms "slow" motion only made the
9
+ * window wider. `useListMotion > an item that moves while it is still
10
+ * entering slides from where it is shown` lost it in the narrow window
11
+ * on 2026-11-14 (run 43611154547): two clicks took longer than the
12
+ * 600 ms enter, and the item had finished entering before the test
13
+ * looked.
14
+ *
15
+ * Held this long, a motion is still running when the test reads it,
16
+ * whatever the machine is doing. A test that needs the motion **over**
17
+ * says so with `finishMotion`, rather than waiting for a clock.
18
+ */
19
+ export declare const HELD_MOTION = "3600s";
20
+ /**
21
+ * End every finite animation and transition on `element` and beneath
22
+ * it, now.
23
+ *
24
+ * `Animation.finish()` jumps the animation to its end, and the browser
25
+ * then dispatches the same `animationend` or `transitionend` it would
26
+ * have dispatched at the natural end. The hooks under test listen for
27
+ * exactly those, so this exercises their real path — it only removes
28
+ * the wait. The events arrive on the next animation frame, so assert
29
+ * on what they cause with `waitFor`.
30
+ *
31
+ * Infinite animations, such as a spinner's, are skipped, because
32
+ * `finish()` throws on them and nothing waits for them to end.
33
+ */
34
+ export declare const finishMotion: (element: Element) => void;
35
+ //# sourceMappingURL=motion.testHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"motion.testHelpers.d.ts","sourceRoot":"","sources":["../src/motion.testHelpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,WAAW,UAAU,CAAA;AAElC;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,YAAY,GAAI,SAAS,OAAO,KAAG,IAW/C,CAAA"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * A motion length no test outlives: an hour.
3
+ *
4
+ * The motion tests assert what is true **while** something moves — an
5
+ * item still entering, a row still leaving, a slide still in flight —
6
+ * right after a `userEvent` call. Each of those calls is a round trip
7
+ * to the browser driver, and on a shared CI runner one round trip has
8
+ * no upper bound. A 600 ms or 1 500 ms "slow" motion only made the
9
+ * window wider. `useListMotion > an item that moves while it is still
10
+ * entering slides from where it is shown` lost it in the narrow window
11
+ * on 2026-11-14 (run 43611154547): two clicks took longer than the
12
+ * 600 ms enter, and the item had finished entering before the test
13
+ * looked.
14
+ *
15
+ * Held this long, a motion is still running when the test reads it,
16
+ * whatever the machine is doing. A test that needs the motion **over**
17
+ * says so with `finishMotion`, rather than waiting for a clock.
18
+ */
19
+ export const HELD_MOTION = "3600s";
20
+ /**
21
+ * End every finite animation and transition on `element` and beneath
22
+ * it, now.
23
+ *
24
+ * `Animation.finish()` jumps the animation to its end, and the browser
25
+ * then dispatches the same `animationend` or `transitionend` it would
26
+ * have dispatched at the natural end. The hooks under test listen for
27
+ * exactly those, so this exercises their real path — it only removes
28
+ * the wait. The events arrive on the next animation frame, so assert
29
+ * on what they cause with `waitFor`.
30
+ *
31
+ * Infinite animations, such as a spinner's, are skipped, because
32
+ * `finish()` throws on them and nothing waits for them to end.
33
+ */
34
+ export const finishMotion = (element) => {
35
+ for (const animation of element.getAnimations({
36
+ subtree: true,
37
+ })) {
38
+ if (animation.effect?.getComputedTiming().endTime !==
39
+ Number.POSITIVE_INFINITY) {
40
+ animation.finish();
41
+ }
42
+ }
43
+ };
44
+ //# sourceMappingURL=motion.testHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"motion.testHelpers.js","sourceRoot":"","sources":["../src/motion.testHelpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAA;AAElC;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAgB,EAAQ,EAAE;IACrD,KAAK,MAAM,SAAS,IAAI,OAAO,CAAC,aAAa,CAAC;QAC5C,OAAO,EAAE,IAAI;KACd,CAAC,EAAE,CAAC;QACH,IACE,SAAS,CAAC,MAAM,EAAE,iBAAiB,EAAE,CAAC,OAAO;YAC7C,MAAM,CAAC,iBAAiB,EACxB,CAAC;YACD,SAAS,CAAC,MAAM,EAAE,CAAA;QACpB,CAAC;IACH,CAAC;AACH,CAAC,CAAA"}
@@ -0,0 +1,52 @@
1
+ import type { RefCallback } from "react";
2
+ /**
3
+ * Whether the photo at `src` has failed, and the two props an `<img>`
4
+ * needs so that every failure is noticed.
5
+ *
6
+ * Shared by `Avatar` and `PortraitTiles`, whose whole promise about a
7
+ * photo is the same: it is never the only thing, so a 404, an expired
8
+ * signed URL, or a wrong content type lands on the initials rather than
9
+ * on a broken-image glyph.
10
+ *
11
+ * ### The failed URL, not a boolean
12
+ *
13
+ * A `hasFailed` boolean has to be *reset* when `src` changes, which is
14
+ * an effect syncing a prop into state — the shape this library refuses
15
+ * ([decision](../../../docs/decisions/2026-07-29-logic-hooks-are-uncontrolled.md)).
16
+ * Storing the URL that failed makes the comparison derive the answer:
17
+ * a new URL gets its own attempt, and a re-render never resurrects a
18
+ * dead one. `PortraitTiles` kept a boolean, so a tile whose photo
19
+ * failed showed initials for the rest of its life, even after the
20
+ * caller passed a working URL.
21
+ *
22
+ * ### `onError` alone misses a failure that happened first
23
+ *
24
+ * React attaches `onError` before it sets `src` on an image it creates,
25
+ * so a client render never misses the event. A **server-rendered**
26
+ * image is different. The browser starts loading it while it parses
27
+ * the HTML, and it can fail before `hydrateRoot` attaches the listener.
28
+ * React does not set `src` again when it hydrates an image, so the
29
+ * `error` event is never repeated, and the broken glyph stays.
30
+ *
31
+ * The ref closes that gap. When React attaches it, an image that is
32
+ * already `complete` has already answered, so `decode()` is asked for
33
+ * the answer again: it rejects for a broken image and resolves for a
34
+ * loaded one. An image still loading is not `complete`, and its answer
35
+ * arrives through `onError` as usual.
36
+ *
37
+ * ⚠️ `decode()` **also rejects when a newer `src` supersedes it**, with
38
+ * the same `EncodingError` a broken image gets. So a rejection counts
39
+ * only while this ref is still the one attached — React runs the
40
+ * cleanup below when the ref detaches or `src` changes — and only
41
+ * while the element still shows that `src` and has finished with it.
42
+ * Without the guard, a picture that was swapped out mid-decode was
43
+ * marked dead, and coming back to it showed the initials.
44
+ */
45
+ export declare const useImageFailure: (src: string | undefined) => {
46
+ hasFailed: boolean;
47
+ imageProps: {
48
+ onError: () => void;
49
+ ref: RefCallback<HTMLImageElement>;
50
+ };
51
+ };
52
+ //# sourceMappingURL=useImageFailure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useImageFailure.d.ts","sourceRoot":"","sources":["../src/useImageFailure.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,OAAO,CAAA;AAGxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,eAAO,MAAM,eAAe,GAC1B,KAAK,MAAM,GAAG,SAAS,KACtB;IACD,SAAS,EAAE,OAAO,CAAA;IAClB,UAAU,EAAE;QACV,OAAO,EAAE,MAAM,IAAI,CAAA;QACnB,GAAG,EAAE,WAAW,CAAC,gBAAgB,CAAC,CAAA;KACnC,CAAA;CAuCF,CAAA"}
@@ -0,0 +1,71 @@
1
+ import { useCallback, useState } from "react";
2
+ /**
3
+ * Whether the photo at `src` has failed, and the two props an `<img>`
4
+ * needs so that every failure is noticed.
5
+ *
6
+ * Shared by `Avatar` and `PortraitTiles`, whose whole promise about a
7
+ * photo is the same: it is never the only thing, so a 404, an expired
8
+ * signed URL, or a wrong content type lands on the initials rather than
9
+ * on a broken-image glyph.
10
+ *
11
+ * ### The failed URL, not a boolean
12
+ *
13
+ * A `hasFailed` boolean has to be *reset* when `src` changes, which is
14
+ * an effect syncing a prop into state — the shape this library refuses
15
+ * ([decision](../../../docs/decisions/2026-07-29-logic-hooks-are-uncontrolled.md)).
16
+ * Storing the URL that failed makes the comparison derive the answer:
17
+ * a new URL gets its own attempt, and a re-render never resurrects a
18
+ * dead one. `PortraitTiles` kept a boolean, so a tile whose photo
19
+ * failed showed initials for the rest of its life, even after the
20
+ * caller passed a working URL.
21
+ *
22
+ * ### `onError` alone misses a failure that happened first
23
+ *
24
+ * React attaches `onError` before it sets `src` on an image it creates,
25
+ * so a client render never misses the event. A **server-rendered**
26
+ * image is different. The browser starts loading it while it parses
27
+ * the HTML, and it can fail before `hydrateRoot` attaches the listener.
28
+ * React does not set `src` again when it hydrates an image, so the
29
+ * `error` event is never repeated, and the broken glyph stays.
30
+ *
31
+ * The ref closes that gap. When React attaches it, an image that is
32
+ * already `complete` has already answered, so `decode()` is asked for
33
+ * the answer again: it rejects for a broken image and resolves for a
34
+ * loaded one. An image still loading is not `complete`, and its answer
35
+ * arrives through `onError` as usual.
36
+ *
37
+ * ⚠️ `decode()` **also rejects when a newer `src` supersedes it**, with
38
+ * the same `EncodingError` a broken image gets. So a rejection counts
39
+ * only while this ref is still the one attached — React runs the
40
+ * cleanup below when the ref detaches or `src` changes — and only
41
+ * while the element still shows that `src` and has finished with it.
42
+ * Without the guard, a picture that was swapped out mid-decode was
43
+ * marked dead, and coming back to it showed the initials.
44
+ */
45
+ export const useImageFailure = (src) => {
46
+ const [failedSrc, setFailedSrc] = useState(undefined);
47
+ const onError = useCallback(() => {
48
+ setFailedSrc(src);
49
+ }, [src]);
50
+ const ref = useCallback((image) => {
51
+ if (image === null || !image.complete) {
52
+ return;
53
+ }
54
+ let isAttached = true;
55
+ image.decode().catch(() => {
56
+ if (isAttached &&
57
+ image.complete &&
58
+ image.getAttribute("src") === src) {
59
+ setFailedSrc(src);
60
+ }
61
+ });
62
+ return () => {
63
+ isAttached = false;
64
+ };
65
+ }, [src]);
66
+ return {
67
+ hasFailed: src !== undefined && failedSrc === src,
68
+ imageProps: { onError, ref },
69
+ };
70
+ };
71
+ //# sourceMappingURL=useImageFailure.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useImageFailure.js","sourceRoot":"","sources":["../src/useImageFailure.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAA;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,GAAuB,EAOvB,EAAE;IACF,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAExC,SAAS,CAAC,CAAA;IAEZ,MAAM,OAAO,GAAG,WAAW,CAAC,GAAG,EAAE;QAC/B,YAAY,CAAC,GAAG,CAAC,CAAA;IACnB,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAA;IAET,MAAM,GAAG,GAAG,WAAW,CACrB,CAAC,KAA8B,EAAE,EAAE;QACjC,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YACtC,OAAM;QACR,CAAC;QAED,IAAI,UAAU,GAAG,IAAI,CAAA;QAErB,KAAK,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,GAAG,EAAE;YACxB,IACE,UAAU;gBACV,KAAK,CAAC,QAAQ;gBACd,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,GAAG,EACjC,CAAC;gBACD,YAAY,CAAC,GAAG,CAAC,CAAA;YACnB,CAAC;QACH,CAAC,CAAC,CAAA;QAEF,OAAO,GAAG,EAAE;YACV,UAAU,GAAG,KAAK,CAAA;QACpB,CAAC,CAAA;IACH,CAAC,EACD,CAAC,GAAG,CAAC,CACN,CAAA;IAED,OAAO;QACL,SAAS,EAAE,GAAG,KAAK,SAAS,IAAI,SAAS,KAAK,GAAG;QACjD,UAAU,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE;KAC7B,CAAA;AACH,CAAC,CAAA"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Resolve once every `<img>` under `root` has **finished**: loaded, or
3
+ * failed.
4
+ *
5
+ * This is the readiness signal for a test about an image, and it has
6
+ * no clock of its own. A `waitFor` around "the broken photo is gone"
7
+ * puts Testing Library's 1 s default on the **network**: the browser
8
+ * has to ask the dev server for the file and hear back 404 before
9
+ * `onError` can run. On a quiet machine that is a few milliseconds.
10
+ * On a shared CI runner, with four browser windows and the whole
11
+ * suite going through one Vite server, it is whenever that server
12
+ * gets to it — `Avatar > a photo that fails falls back to the
13
+ * initials` failed in the ultrawide window on the first run of #427
14
+ * with the `<img>` still in place after 1.37 s, and passed on the
15
+ * re-run. `PortraitTiles` had already hit the same wall, and had
16
+ * been given five seconds instead of a signal.
17
+ *
18
+ * So the wait is on the browser's own answer instead: the `load` or
19
+ * `error` event, or `complete` when that answer arrived before the
20
+ * test looked. `complete` is `true` for a **broken** image as well as
21
+ * a loaded one, which is the property this relies on.
22
+ *
23
+ * The listeners are added after the component's own, so a component
24
+ * that handles `onError` has already run its handler by the time this
25
+ * resolves. What is left is the component's own re-render, which a
26
+ * plain `waitFor` covers — that is page work, not network.
27
+ *
28
+ * The only budget left is the test's own timeout. An image that never
29
+ * finishes, such as a `loading="lazy"` one off-screen, holds the test
30
+ * until then; no story in this library has one.
31
+ */
32
+ export declare const waitForImagesToFinish: (root: ParentNode) => Promise<void>;
33
+ //# sourceMappingURL=waitForImages.testHelpers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"waitForImages.testHelpers.d.ts","sourceRoot":"","sources":["../src/waitForImages.testHelpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,qBAAqB,GAChC,MAAM,UAAU,KACf,OAAO,CAAC,IAAI,CAMd,CAAA"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Resolve once every `<img>` under `root` has **finished**: loaded, or
3
+ * failed.
4
+ *
5
+ * This is the readiness signal for a test about an image, and it has
6
+ * no clock of its own. A `waitFor` around "the broken photo is gone"
7
+ * puts Testing Library's 1 s default on the **network**: the browser
8
+ * has to ask the dev server for the file and hear back 404 before
9
+ * `onError` can run. On a quiet machine that is a few milliseconds.
10
+ * On a shared CI runner, with four browser windows and the whole
11
+ * suite going through one Vite server, it is whenever that server
12
+ * gets to it — `Avatar > a photo that fails falls back to the
13
+ * initials` failed in the ultrawide window on the first run of #427
14
+ * with the `<img>` still in place after 1.37 s, and passed on the
15
+ * re-run. `PortraitTiles` had already hit the same wall, and had
16
+ * been given five seconds instead of a signal.
17
+ *
18
+ * So the wait is on the browser's own answer instead: the `load` or
19
+ * `error` event, or `complete` when that answer arrived before the
20
+ * test looked. `complete` is `true` for a **broken** image as well as
21
+ * a loaded one, which is the property this relies on.
22
+ *
23
+ * The listeners are added after the component's own, so a component
24
+ * that handles `onError` has already run its handler by the time this
25
+ * resolves. What is left is the component's own re-render, which a
26
+ * plain `waitFor` covers — that is page work, not network.
27
+ *
28
+ * The only budget left is the test's own timeout. An image that never
29
+ * finishes, such as a `loading="lazy"` one off-screen, holds the test
30
+ * until then; no story in this library has one.
31
+ */
32
+ export const waitForImagesToFinish = async (root) => {
33
+ await Promise.all(Array.from(root.querySelectorAll("img"), (image) => waitForImageToFinish(image)));
34
+ };
35
+ const waitForImageToFinish = (image) => new Promise((resolve) => {
36
+ if (image.complete) {
37
+ resolve();
38
+ return;
39
+ }
40
+ const finish = () => {
41
+ image.removeEventListener("error", finish);
42
+ image.removeEventListener("load", finish);
43
+ resolve();
44
+ };
45
+ image.addEventListener("error", finish);
46
+ image.addEventListener("load", finish);
47
+ });
48
+ //# sourceMappingURL=waitForImages.testHelpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"waitForImages.testHelpers.js","sourceRoot":"","sources":["../src/waitForImages.testHelpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,EACxC,IAAgB,EACD,EAAE;IACjB,MAAM,OAAO,CAAC,GAAG,CACf,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,gBAAgB,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,EAAE,CACjD,oBAAoB,CAAC,KAAK,CAAC,CAC5B,CACF,CAAA;AACH,CAAC,CAAA;AAED,MAAM,oBAAoB,GAAG,CAC3B,KAAuB,EACR,EAAE,CACjB,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;IACtB,IAAI,KAAK,CAAC,QAAQ,EAAE,CAAC;QACnB,OAAO,EAAE,CAAA;QAET,OAAM;IACR,CAAC;IAED,MAAM,MAAM,GAAG,GAAG,EAAE;QAClB,KAAK,CAAC,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;QAC1C,KAAK,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QAEzC,OAAO,EAAE,CAAA;IACX,CAAC,CAAA;IAED,KAAK,CAAC,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC,CAAA;IACvC,KAAK,CAAC,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;AACxC,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@charcuterie/ui",
3
- "version": "4.28.2",
3
+ "version": "4.28.4",
4
4
  "description": "The Charcuterie components. Tokens for look, @charcuterie/logic for state, ARIA that agents can actually drive.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -58,7 +58,7 @@
58
58
  ],
59
59
  "dependencies": {
60
60
  "@charcuterie/logic": "2.12.0",
61
- "@charcuterie/tokens": "1.10.2",
61
+ "@charcuterie/tokens": "1.10.3",
62
62
  "@floating-ui/react": "^0.27.20",
63
63
  "@tanstack/react-virtual": "^3.13.12",
64
64
  "tailwind-merge": "^3.6.0"
@@ -130,7 +130,7 @@
130
130
  }
131
131
  },
132
132
  "devDependencies": {
133
- "@charcuterie/storybook-config": "0.4.3",
133
+ "@charcuterie/storybook-config": "0.4.4",
134
134
  "@charcuterie/vitest-config": "^2.0.0",
135
135
  "@codemirror/commands": "^6",
136
136
  "@codemirror/lang-markdown": "^6",
@@ -1,11 +1,15 @@
1
1
  import { composeStories } from "@storybook/react"
2
+ import { hydrateRoot } from "react-dom/client"
3
+ import { renderToString } from "react-dom/server"
2
4
  import { expect, waitFor } from "storybook/test"
3
5
  import { test } from "vitest"
4
6
 
5
7
  import { expectNoAxeViolations } from "../expectNoAxeViolations.testHelpers.ts"
6
8
  import { mountStory } from "../mountStory.testHelpers.ts"
7
9
  import { expectAgentDrivable } from "../testing/index.ts"
10
+ import { waitForImagesToFinish } from "../waitForImages.testHelpers.ts"
8
11
  import * as stories from "./Avatar.stories.tsx"
12
+ import { Avatar } from "./Avatar.tsx"
9
13
 
10
14
  const { AllStates, AllVariants, Playground, InAList } =
11
15
  composeStories(stories)
@@ -79,13 +83,20 @@ test("an unassigned avatar renders nothing at all", async () => {
79
83
  * because nobody writes the `onError` until they see it.
80
84
  */
81
85
  test("a photo that fails falls back to the initials", async () => {
82
- const { canvas } = await mountStory(AllStates)
86
+ const { canvas, canvasElement } =
87
+ await mountStory(AllStates)
83
88
 
84
89
  const broken = expectAgentDrivable(canvas, {
85
90
  name: "Kit Sandoval",
86
91
  role: "img",
87
92
  })
88
93
 
94
+ // Wait for the browser's answer about each photo, not for a clock:
95
+ // the 404 comes back from the dev server whenever it gets to it,
96
+ // and on a shared CI runner that was later than `waitFor`'s 1 s.
97
+ // What is left after it is the component's own re-render.
98
+ await waitForImagesToFinish(canvasElement)
99
+
89
100
  await waitFor(async () => {
90
101
  await expect(broken.querySelector("img")).toBeNull()
91
102
  })
@@ -109,6 +120,48 @@ test("a photo that fails falls back to the initials", async () => {
109
120
  )
110
121
  })
111
122
 
123
+ /**
124
+ * The same promise for a server render, where `onError` alone cannot
125
+ * keep it. The browser loads a server-rendered photo while it parses
126
+ * the HTML, so a 404 can land before `hydrateRoot` attaches the
127
+ * listener, and React does not set `src` again to repeat it. Without
128
+ * the check `useImageFailure` makes when React attaches its ref, the
129
+ * broken-image glyph stays for good.
130
+ */
131
+ test("a photo that failed before hydration still falls back to the initials", async () => {
132
+ const avatar = (
133
+ <Avatar
134
+ imageUrl="/charcuterie-missing-portrait.png"
135
+ name="Kit Sandoval"
136
+ />
137
+ )
138
+
139
+ const host = document.createElement("div")
140
+
141
+ document.body.append(host)
142
+
143
+ host.innerHTML = renderToString(avatar)
144
+
145
+ // The photo has failed, and nothing was listening yet.
146
+ await waitForImagesToFinish(host)
147
+
148
+ await expect(host.querySelector("img")).not.toBeNull()
149
+
150
+ const root = hydrateRoot(host, avatar)
151
+
152
+ try {
153
+ await waitFor(async () => {
154
+ await expect(host.querySelector("img")).toBeNull()
155
+ })
156
+
157
+ await expect(host).toHaveTextContent("KS")
158
+ } finally {
159
+ root.unmount()
160
+
161
+ host.remove()
162
+ }
163
+ })
164
+
112
165
  /**
113
166
  * The colour is a pure function of the key, so the same person is
114
167
  * the same colour in every appearance, on every machine, and in a