Vitest에 이상한 거 제안하는 중
코드:
test("streaming ssr", async () => {
const Comp = (props) => {
const data = createAsync(() => props.promise);
return (
<Suspense fallback="Loading...">
<span>Data: {data()}</span>
</Suspense>
);
};
const stream = await run$("server", async (ctx) => {
const { promise, resolve } = Promise.withResolvers();
ctx.set("resolve", resolve);
return renderToStream(() => <Comp promise={promise} />);
});
await run$("client", async () => {
hydrate(stream, document.body);
});
await expect$("client").element(page.getByText("Loading...")).toBeInTheDocument();
await run$("server", async (ctx) => {
const resolve = ctx.get("resolve");
resolve(42);
});
await expect$("client").element(page.getByText("Data: 42")).toBeInTheDocument();
await expect$("client").element(page.getByText("Loading...")).not.toBeInTheDocument();
})
If you have a fediverse account, you can quote this note from your own instance. Search https://hackers.pub/ap/notes/019613a7-0e74-7db7-a9d0-c8fe8a443e53 on your instance and quote it. (Note that quoting is not supported in Mastodon.)