-
Notifications
You must be signed in to change notification settings - Fork 401
Closed
Labels
Description
Duplicates
- I have searched the existing issues
Latest version
- I have tested the latest version
Current behavior 😯
Adding the "use server" directive to an async generator fails with the error "use server" in generator function not supported.
The error is raised from the plugin tanstack-start-directive-vite-plugin
Error location is @tanstack/directive-functions-plugin/dist/esm/compilers.js:327:10
Version of @tanstack/directive-functions-plugin is 1.115.0
Expected behavior 🤔
"use server" in async generator functions should work. And it did work before adopting @tanstack/server-functions-plugin in #1715
And indeed, if you hoist "use server" to the module level, the functionality DOES work even today, but then you get warnings about module-level "use server" being unsupported when you run pnpm run build, which I think is an otherwise unrelated issue (#1799).
Steps to reproduce 🕹
Steps:
pnpm create solid- Create a SolidStart project using the
basictemplate. - Add the following files:
/* src/server-functions.tsx */
// Say hello in a different language every second, forever.
export async function* sayHello() {
"use server";
const greetings = [
"Hello, World!", // English
"¡Hola, Mundo!", // Spanish
"Bonjour le monde !", // French
"Hallo Welt!", // German
"Ciao mondo!", // Italian
"Olá Mundo!", // Portuguese
"こんにちは世界", // Japanese
"你好,世界" // Chinese (Mandarin)
];
for (const greeting of greetings) {
yield greeting;
await new Promise(resolve => setTimeout(resolve, 1000)); // Wait for 1 second
}
}/* src/routes/generator-server-fn.tsx */
import { Title } from "@solidjs/meta";
import { For, onMount } from "solid-js";
import { createStore } from "solid-js/store";
import { sayHello } from '~/server-functions';
export default function GeneratorServerFn() {
const [store, setStore] = createStore<Array<string>>([]);
onMount(async () => {
const greetings = await sayHello();
for await (const greeting of greetings) {
setStore(store.length, greeting);
}
});
return (
<main>
<Title>Generator Server Fn</Title>
<h1>Generator Server Fn</h1>
<For each={store}>
{(message) => <div class="message">{message}</div>}
</For>
</main>
);
}pnpm run dev- Visit
http://localhost:3000/generator-server-fn - Observe the error
"use server" in generator function not supportedoccurring. - Optional: hoist
"use server"to the top of thesrc/server-functions.tsfile and refresh, and then observe that the server function runs and streams a new "hello, world" phrase to be added to the page every second.
Context 🔦
No response
Your environment 🌎
System:
OS: macOS Sequoia 15.3.2
Chip: Apple M1 Pro
Node.js v22.14.0
pnpm 10.8.0
@solidjs/[email protected]