calcom/cal.com

Query parameters are stripped on redirect from dynamic URLs

Closed this issue · 1 comments

eelco commented

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

  1. 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:

const destinationUrl = `/${usernameList.join("+")}/dynamic`;

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:

  1. Extract the original query parameters from context.query.
  2. Convert these parameters into a query string.
  3. 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


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.