feat(runtime): provide no-op animation scheduler in renderToString
This commit is contained in:
@@ -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");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user