dai-shi / waku

⛩️ The minimal React framework
https://waku.gg
MIT License
4.01k stars 104 forks source link

fix: output AWS Lambda / AWS HTTP API V2 breaks RSC POST requests url needed for server actions #458

Closed aheissenberger closed 3 months ago

aheissenberger commented 3 months ago

This fix is hack to revert the decoded url in the rawPath property provided by the AWS API Gateway with a HTTP API V2 Event.

The hack will only apply to POST request which start with /RSC/.

There is no way to fix this in the Hono layer as an arbitrary decoded Path cannot be encoded back to the same original!

see https://github.com/honojs/hono/issues/2156

Without this fix, the url: new URL(c.req.url), will ignore everything after the # on the decoded url.

default url (e.g. node environment): http://localhost/RSC/%40id%2Fassets%2Frsf0.js%23save.txt

url (AWS API Gateway): http://localhost/RSC/@id/assets/rsf0.js#save.txt

new URL(http://localhost/RSC/@id/assets/rsf0.js#save.txt').pathname => /RSC/@id/assets/rsf0.js missing: #save.txt

https://github.com/dai-shi/waku/blob/32d52242c1450b5f5965860e671ff73c42da8bd0/packages/waku/src/lib/middleware/hono-utils.ts#L49-L63

vercel[bot] commented 3 months ago

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
waku ✅ Ready (Inspect) Visit Preview Feb 6, 2024 8:55pm
codesandbox-ci[bot] commented 3 months ago

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 9f649a643ed6e9fa602fb4094e0ffe4615835241:

Sandbox Source
Vanilla Typescript Configuration
React Configuration
React TypeScript Configuration
aheissenberger commented 3 months ago

Is adding the parameters as url encoded path segment after /RSC/ the official protocol for react server actions?

dai-shi commented 3 months ago

Is adding the parameters as url encoded path segment after /RSC/ the official protocol for react server actions?

It's Waku's protocol.

dai-shi commented 3 months ago

For server components, the current protocol should be mostly fine. But, I'm not 100% happy with the current protocol for server actions. We can revisit it.

aheissenberger commented 3 months ago

Hmm, it seems like the hono issue will be resolved before we make a new release. Can we wait for the upstream fix?

There is no way to resolve this issue - only the team at AWS API Gateway can fix this and I know no way to get this reported.

dai-shi commented 3 months ago

If you can wait, I would like to fix it by avoiding URL encode in Waku core, because I wasn't very happy with it. Please give me some time.

dai-shi commented 3 months ago

@aheissenberger Can you confirm if #463 fixes it?

aheissenberger commented 3 months ago

@aheissenberger Can you confirm if #463 fixes it?

yes - changing the id in the url fixed the problem :-)