feat(runtime): provide no-op animation scheduler in renderToString

This commit is contained in:
Yunfei He
2026-05-28 14:40:21 +08:00
parent 00dcaad206
commit abaf2acbce
2 changed files with 13 additions and 1 deletions
@@ -3,7 +3,7 @@ import { defineComponent, nextTick, shallowRef, watchEffect } from "vue";
import type { ShallowRef } from "vue";
import { describe, expect, test } from "vite-plus/test";
import { render } from "@vue-tui/testing";
import { Text, useAnimation, createApp } from "@vue-tui/runtime";
import { Text, useAnimation, createApp, renderToString } from "@vue-tui/runtime";
const delay = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));
@@ -968,4 +968,13 @@ describe("useAnimation", () => {
unmount();
});
test("renderToString renders frame 0 without throwing or leaking timers", () => {
const App = defineComponent(() => {
const { frame } = useAnimation({ interval: 50 });
return () => <Text>{`frame:${frame.value}`}</Text>;
});
const output = renderToString(App);
expect(output).toContain("frame:0");
});
});
+3
View File
@@ -13,10 +13,12 @@ import {
AppContextKey,
FocusContextKey,
StdinContextKey,
AnimationSchedulerKey,
type AppContext,
type FocusContext,
type StdinContext,
} from "./context.ts";
import { createNoOpAnimationScheduler } from "./animation-scheduler.ts";
export interface RenderToStringOptions {
/**
@@ -94,6 +96,7 @@ export function renderToString(component: Component, options?: RenderToStringOpt
app.provide(AppContextKey, appContext);
app.provide(FocusContextKey, createNoOpFocusContext());
app.provide(StdinContextKey, createNoOpStdinContext());
app.provide(AnimationSchedulerKey, createNoOpAnimationScheduler());
// Capture the first uncaught error so we can re-throw after cleanup.
// Vue's error handling catches component errors internally; for a