Skip to content

fix: reply encoding#2

Merged
dai-shi merged 1 commit intomainfrom
fix/reply-encoding
Mar 14, 2023
Merged

fix: reply encoding#2
dai-shi merged 1 commit intomainfrom
fix/reply-encoding

Conversation

@dai-shi
Copy link
Member

@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

const response = fetch(`/?${searchParams}`, {
method: "POST",
body: JSON.stringify(args),
body: await encodeReply(args),
Copy link
Member 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
Member 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
Member 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
@pkg-pr-new
Copy link

pkg-pr-new bot commented Jul 9, 2025

Open in StackBlitz

npm i https://pkg.pr.new/wakujs/waku@2

commit: 55cc5fb

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