Query parameters are stripped on redirect from dynamic URLs
Closed this issue · 1 comments
Issue Summary
When adding query parameters to a dynamic URL they get stripped as it gets redirected to …/dynamic
(e.g. https://cal.com/foo+bar?duration=60
)
Steps to Reproduce
- Open an URL like
https://cal.com/foo+bar?duration=60
Actual Results
It will redirect to https://cal.com/foo+bar/dynamic
, stripping the query parameters and select the default duration.
Expected Results
It should redirect to https://cal.com/foo+bar/dynamic?duration=60
, retaining the query parameters so the duration is set correctly.
Technical details
The bug is on this line:
Evidence
Trivial to test.
To address the issue of query parameters being stripped on redirect from dynamic URLs, you can modify the redirection logic in the getServerSideProps
function. Here's a concise guide to retain the query parameters like ?duration=60
:
- Extract the original query parameters from
context.query
. - Convert these parameters into a query string.
- Append this query string to the destination URL.
Here's a code snippet to illustrate the changes:
if (isDynamicGroup) {
const destinationUrl = `/${usernameList.join("+")}/dynamic`;
const originalQueryString = new URLSearchParams(context.query as Record<string, string>).toString();
const destinationWithQuery = `${destinationUrl}?${originalQueryString}`;
return {
redirect: {
permanent: false,
destination: destinationWithQuery,
},
} as const;
}
This ensures that the original query parameters are retained in the new URL upon redirection. Make sure to test these changes thoroughly to avoid any unexpected behavior. Additionally, consider updating any relevant tests to reflect this new redirection logic.
Details
Sources
- apps/web/modules/users/views/users-public-view.getServerSideProps.tsx
- apps/web/lib/withEmbedSsr.test.ts
- packages/features/bookings/Booker/utils/query-param.ts
- apps/web/lib/hooks/useRouterQuery.ts
- apps/web/lib/apps/installed/[category]/getServerSideProps.tsx
- packages/app-store/_pages/setup/_getServerSideProps.tsx
- apps/web/modules/bookings/views/bookings-single-view.getServerSideProps.tsx
- apps/web/modules/users/views/users-type-public-view.getServerSideProps.tsx
- apps/web/lib/signup/getServerSideProps.tsx
- packages/types/AppGetServerSideProps.d.ts
- apps/web/server/lib/setup/getServerSideProps.tsx
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
To continue the conversation, mention @dosu.