Skip to content

Code-first video & image, rendered natively on WebGPU.

fix: ChatThread waits for the last reaction; no headless font download in pages

okanasl126fccba96e3
diff --git a/.changeset/chat-reaction-window.md b/.changeset/chat-reaction-window.md
new file mode 100644
index 00000000..baab9c82
--- /dev/null
+++ b/.changeset/chat-reaction-window.md
@@ -0,0 +1,6 @@
+---
+"framefields": patch
+---
+
+- ChatThread lasts until a reaction on the last message has popped. Its natural length ended 0.8 s after the last bubble, but a reaction pops 0.6 s after its bubble and springs for longer, so with an `exit` or a fitted clip the pop was cut off and the reaction never showed.
+- Fonts registered in the browser (the live preview, the docs lab) no longer warn `[registerHeadlessFont] … mkdtemp is not a function`: the Node-only local copy is skipped in a page, where text draws from the registered source. Headless `file://` font paths with spaces resolve too.
diff --git a/packages/components/src/chat-thread/index.test.ts b/packages/components/src/chat-thread/index.test.ts
index 8c4eceb7..1f23dd49 100644
--- a/packages/components/src/chat-thread/index.test.ts
+++ b/packages/components/src/chat-thread/index.test.ts
@@ -59,6 +59,36 @@ describe("ChatThread", () => {
);
});
+ it("lasts until a reaction on the last message has popped", () => {
+ const node = make()({
+ id: "r",
+ messages: [
+ { from: "me", text: "Shipped?" },
+ { from: "sam", text: "Ship it", reaction: "🚀" },
+ ],
+ exit: "fade",
+ hold: 0,
+ });
+ /** Latest keyframe anywhere in the tree (local frames; the root starts at 0). */
+ const last = (n: unknown): number => {
+ const x = n as {
+ animation?: {
+ tracks?: Array<{ keyframes?: Array<{ frame: number }> }>;
+ };
+ children?: unknown[];
+ };
+ const own = (x.animation?.tracks ?? []).flatMap((t) =>
+ (t.keyframes ?? []).map((k) => k.frame),
+ );
+ return Math.max(0, ...own, ...(x.children ?? []).map(last));
+ };
+ const landed = node.cues.messages[1]?.frame ?? 0;
+ expect(find(node, "r-reaction-1")).toBeDefined();
+ expect(last(node)).toBeLessThanOrEqual(node.span.duration);
+ // The pop is why: it starts 0.6 s after the bubble and springs for longer than 0.8 s.
+ expect(node.span.duration).toBeGreaterThan(landed + 24 + 16);
+ });
+
it("shows avatars for others once anyone has a picture, initials otherwise", () => {
const avatarMessages = [
{ from: "me", text: "Shipped?" },
diff --git a/packages/components/src/chat-thread/index.ts b/packages/components/src/chat-thread/index.ts
index 32f87058..2f13e2d0 100644
--- a/packages/components/src/chat-thread/index.ts
+++ b/packages/components/src/chat-thread/index.ts
@@ -10,7 +10,7 @@ import {
type LayoutNode,
} from "@framefields/compositions/program";
import { z } from "zod";
-import { springKeys } from "../core/bake.js";
+import { springKeys, springSettleFrames } from "../core/bake.js";
import { defineComponent } from "../core/contract.js";
import type { Animatable } from "../core/host.js";
import { supersede } from "../core/keys.js";
@@ -93,6 +93,8 @@ export const chatThread = /* @__PURE__ */ defineComponent({
const { host, theme, fps } = ctx;
// Bubbles overshoot a little; reactions bounce.
const { base: spring, pop } = theme.motion.spring;
+ /** The last frame anything moves: reactions pop after their bubble lands. */
+ let settled = 0;
const s = theme.scale;
const W = ctx.requested.width ?? 720 * s;
const H = ctx.requested.height ?? 960 * s;
@@ -407,6 +409,7 @@ export const chatThread = /* @__PURE__ */ defineComponent({
const rh = fs * 1.5;
const rw = Math.max(rh, rm.width + fs * 0.6);
const rAt = at + Math.round(fps * 0.6);
+ settled = Math.max(settled, rAt + springSettleFrames(fps, pop));
const border = Math.max(2, fs * 0.1);
// On the outer top corner, like a tapback.
const pill = host.box({
@@ -679,7 +682,7 @@ export const chatThread = /* @__PURE__ */ defineComponent({
children: [viewport],
width: W,
height: H,
- duration: lastAt + Math.round(fps * 0.8),
+ duration: Math.max(lastAt + Math.round(fps * 0.8), settled),
openEnded: true,
cues: {
messages: landed.map((frame, index) => ({
diff --git a/packages/webgpu-renderers/src/headless-font-loader.test.ts b/packages/webgpu-renderers/src/headless-font-loader.test.ts
index 8c06000a..4a8bc802 100644
--- a/packages/webgpu-renderers/src/headless-font-loader.test.ts
+++ b/packages/webgpu-renderers/src/headless-font-loader.test.ts
@@ -42,3 +42,31 @@ describe("clearHeadlessFonts", () => {
expect(existsSync(path.dirname(file as string))).toBe(false);
});
});
+
+describe("registerHeadlessFont", () => {
+ afterEach(async () => {
+ vi.unstubAllGlobals();
+ vi.restoreAllMocks();
+ await clearHeadlessFonts();
+ });
+
+ it("decodes file:// URLs, so paths with spaces resolve", async () => {
+ expect(
+ await registerHeadlessFont("Spaced", "file:///a/My%20Film/Inter.ttf"),
+ ).toBe("/a/My Film/Inter.ttf");
+ });
+
+ it("does nothing in a browser page: no download, no warning", async () => {
+ vi.stubGlobal("window", globalThis);
+ vi.stubGlobal("document", {});
+ const fetch = vi.fn();
+ vi.stubGlobal("fetch", fetch);
+ const warn = vi.spyOn(console, "warn").mockImplementation(() => {});
+ expect(
+ await registerHeadlessFont("Inter", "http://localhost/assets/Inter.ttf"),
+ ).toBeUndefined();
+ expect(fetch).not.toHaveBeenCalled();
+ expect(warn).not.toHaveBeenCalled();
+ expect(getHeadlessFontPath("Inter")).toBeUndefined();
+ });
+});
diff --git a/packages/webgpu-renderers/src/headless-font-loader.ts b/packages/webgpu-renderers/src/headless-font-loader.ts
index 88598929..a1291ddd 100644
--- a/packages/webgpu-renderers/src/headless-font-loader.ts
+++ b/packages/webgpu-renderers/src/headless-font-loader.ts
@@ -23,7 +23,8 @@ async function getLocalFontPath(family: string, url: string): Promise<string> {
if (resolvedUrl.startsWith("file://")) {
try {
- let fontPath = new URL(resolvedUrl).pathname;
+ // A URL path is percent-encoded ("My%20Film"); files aren't.
+ let fontPath = decodeURIComponent(new URL(resolvedUrl).pathname);
if (process.platform === "win32" && fontPath.startsWith("/")) {
fontPath = fontPath.slice(1);
}
@@ -98,10 +99,25 @@ export async function clearHeadlessFonts(): Promise<void> {
}
}
+/**
+ * A browser page rather than Node or the headless renderer: there is no
+ * file system, and text draws from the registered source (Slug, FontFace).
+ */
+function inBrowserPage(): boolean {
+ return (
+ !(globalThis as Record<string, unknown>).__IS_HEADLESS_RENDERER__ &&
+ typeof window !== "undefined" &&
+ typeof globalThis.document !== "undefined"
+ );
+}
+
export async function registerHeadlessFont(
family: string,
url: string,
): Promise<string | undefined> {
+ // The local copy is for skia-canvas and DotLottie in Node; a page would
+ // only try (and warn about) a temp-dir download it can't make.
+ if (inBrowserPage()) return undefined;
if (fontPaths.has(family)) {
return fontPaths.get(family);
}