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

experimental GET support #947

Merged
merged 1 commit into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions packages/waku/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const defaultFetchCache: FetchCache = {};
*/
export const callServerRsc = async (
funcId: string,
args?: unknown[],
args: unknown[],
fetchCache = defaultFetchCache,
) => {
const enhanceCreateData = fetchCache[ENHANCE_CREATE_DATA] || ((d) => d);
Expand All @@ -112,8 +112,8 @@ export const callServerRsc = async (
});
const url = BASE_PATH + encodeRscPath(encodeFuncId(funcId));
const responsePromise =
args === undefined
? fetch(url)
args.length === 1 && args[0] instanceof URLSearchParams
? fetch(url + '?' + args[0])
: encodeReply(args).then((body) => fetch(url, { method: 'POST', body }));
const data = enhanceCreateData(createData)(responsePromise);
// FIXME this causes rerenders even if data is empty
Expand All @@ -126,8 +126,8 @@ const prefetchedParams = new WeakMap<Promise<unknown>, unknown>();
const fetchRscInternal = (url: string, rscParams: unknown) =>
rscParams === undefined
? fetch(url)
: typeof rscParams === 'string'
? fetch(url, { headers: { 'X-Waku-Params': rscParams } })
: rscParams instanceof URLSearchParams
? fetch(url + '?' + rscParams)
: encodeReply(rscParams).then((body) =>
fetch(url, { method: 'POST', body }),
);
Expand Down
2 changes: 1 addition & 1 deletion packages/waku/src/lib/middleware/rsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const rsc: Middleware = (options) => {
config,
rscPath,
context: ctx.context,
decodedBody: headers['x-waku-params'],
decodedBody: ctx.req.url.searchParams,
body: ctx.req.body,
contentType: headers['content-type'] || '',
};
Expand Down
6 changes: 5 additions & 1 deletion packages/waku/src/lib/renderers/rsc-renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,11 @@ export async function renderRsc(

const funcId = decodeFuncId(rscPath);
if (funcId) {
const args = Array.isArray(decodedBody) ? decodedBody : [];
const args = Array.isArray(decodedBody)
? decodedBody
: decodedBody instanceof URLSearchParams
? [decodedBody]
: [];
const [fileId, name] = funcId.split('#') as [string, string];
let mod: any;
if (isDev) {
Expand Down
Loading