Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reply encoding #2

Merged
merged 1 commit into from
Mar 14, 2023
Merged

fix: reply encoding #2

merged 1 commit into from
Mar 14, 2023

Conversation

dai-shi
Copy link
Owner

@dai-shi dai-shi commented Mar 13, 2023

@codesandbox-ci
Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit d5d12c9:

Sandbox Source
Vanilla Configuration
Vanilla Typescript Configuration
React Configuration
React Typescript Configuration

@@ -19,7 +20,7 @@ export function serve<Props>(rscId: string, render: (ele: ReactNode) => void) {
}
const response = fetch(`/?${searchParams}`, {
method: "POST",
body: JSON.stringify(args),
body: await encodeReply(args),
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if doing this will set content-type header for form data.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works.

@dai-shi
Copy link
Owner Author

dai-shi commented Mar 14, 2023

Did an experiment:

diff --git a/examples/04_callserver/src/Counter.tsx b/examples/04_callserver/src/Counter.tsx
index c55c50d..d0dac48 100644
--- a/examples/04_callserver/src/Counter.tsx
+++ b/examples/04_callserver/src/Counter.tsx
@@ -21,6 +21,18 @@ export const Counter = ({
         >
           greet("client:" + count) = {text}
         </button>
+        <button
+          onClick={async () => {
+            const res = await greet(
+              new Promise((resolve) =>
+                setTimeout(() => resolve("from promise"), 1000)
+              )
+            );
+            console.log(res);
+          }}
+        >
+          greet with delay
+        </button>
       </p>
       <h3>This is a client component.</h3>
     </div>
diff --git a/examples/04_callserver/src/funcs.ts b/examples/04_callserver/src/funcs.ts
index 119d09f..d7540fb 100644
--- a/examples/04_callserver/src/funcs.ts
+++ b/examples/04_callserver/src/funcs.ts
@@ -1,3 +1,3 @@
 "use server";
 
-export const greet = (name: string) => `Hello ${name} from server!`;
+export const greet = async (name: string) => `Hello ${await name} from server!`;

image

image

image

@dai-shi dai-shi merged commit 00c1906 into main Mar 14, 2023
@dai-shi dai-shi deleted the fix/reply-encoding branch March 14, 2023 00:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant