Skip to content

Commit b7c174c

Browse files
authored
fix: generators with server functions (#1888)
1 parent 8ef3aeb commit b7c174c

File tree

6 files changed

+162
-133
lines changed

6 files changed

+162
-133
lines changed

packages/start/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
"vinxi": "^0.5.3"
6464
},
6565
"dependencies": {
66-
"@tanstack/server-functions-plugin": "^1.105.2",
66+
"@tanstack/server-functions-plugin": "^1.119.2",
6767
"@vinxi/plugin-directives": "^0.5.0",
6868
"@vinxi/server-components": "^0.5.0",
6969
"defu": "^6.1.2",

packages/tests/cypress/e2e/server-function.cy.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,8 @@ describe("server-function", () => {
4848
cy.visit("is-server-with-anon-default-export");
4949
cy.get("#server-fn-test").contains('{"serverFnWithIsServer":true}');
5050
});
51+
it("should build with generator as server function", () => {
52+
cy.visit("/generator-server-function");
53+
cy.get("#server-fn-test").contains('¡Hola, Mundo!');
54+
});
5155
});

packages/tests/src/app.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ export default function App() {
4747
<li>
4848
<a href="/is-server-with-anon-default-export">is server with anon default export</a>
4949
</li>
50+
<li>
51+
<a href="/generator-server-function">generator server function</a>
52+
</li>
5053
</ul>
5154
<Suspense>{props.children}</Suspense>
5255
</MetaProvider>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
export async function* sayHello() {
2+
"use server";
3+
yield "Hello, World!";
4+
yield "¡Hola, Mundo!";
5+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { createSignal, onMount } from "solid-js";
2+
import { sayHello } from '~/functions/use-generator-server-function';
3+
4+
export default function GeneratorServerFunction() {
5+
const [output, setOutput] = createSignal<string>('');
6+
7+
onMount(async () => {
8+
const greetings = await sayHello();
9+
for await (const greeting of greetings) {
10+
setOutput(greeting);
11+
}
12+
});
13+
14+
return (
15+
<main>
16+
<div id="server-fn-test">{output()}</div>
17+
</main>
18+
);
19+
}

0 commit comments

Comments
 (0)