Skip to content

Commit

Permalink
chore: workaround export let count
Browse files Browse the repository at this point in the history
  • Loading branch information
hi-ogawa committed May 28, 2024
1 parent d4afe0e commit 49ee1b1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
3 changes: 3 additions & 0 deletions examples/react-server/src/features/server-action/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ export function registerServerReference(
id: string,
name: string,
) {
if (typeof action !== "function") {
return action;
}
return ReactServer.registerServerReference(action, id, name);
}

Expand Down
7 changes: 6 additions & 1 deletion examples/react-server/src/routes/action/_action.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
"use server";

export let count1 = 0;
// TODO: support `export let ...` and preserve reference;
let count1 = 0;

export function getCount1() {
return count1;
}

export function changeCount1(formData: FormData) {
count1 += Number(formData.get("value"));
Expand Down
4 changes: 2 additions & 2 deletions examples/react-server/src/routes/action/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { changeCount1, count1 } from "./_action";
import { changeCount1, getCount1 } from "./_action";
import { Counter3 } from "./_client";

export default function Page() {
Expand All @@ -10,7 +10,7 @@ export default function Page() {
"use server" file + server component
</h4>
<form action={changeCount1} data-testid="counter1">
<div>Count: {count1}</div>
<div>Count: {getCount1()}</div>
<button name="value" value={-1}>
-1
</button>
Expand Down
2 changes: 0 additions & 2 deletions examples/react-server/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,6 @@ function vitePluginServerAction(): PluginOption {
runtime: "$$register",
});
if (output.hasChanged()) {
console.log({ name: this.environment.name, id }, output.toString());
manager.serverReferences.add(id);
output.prepend(
`import { registerServerReference as $$register } from "/src/features/server-action/server";\n`,
Expand All @@ -336,7 +335,6 @@ function vitePluginServerAction(): PluginOption {
directive: "use server",
});
if (output) {
console.log({ name: this.environment.name, id }, output);
manager.serverReferences.add(id);
const runtime =
this.environment.name === "client" ? "browser" : "ssr";
Expand Down

0 comments on commit 49ee1b1

Please sign in to comment.