fix: Embed Snippet Generator, hard crash on reload (#11363)

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
11576-cal-2537-a11y-turn-booking-entries-in-booking-to-links-not-clickable-divs^2
Hariom Balhara 2023-09-28 23:38:42 +05:30 committed by GitHub
parent fb2c966e6c
commit 2b1918f40a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 8 deletions

View File

@ -29,7 +29,11 @@ class MyDocument extends Document<Props> {
const asPath = ctx.asPath || "";
// Use a dummy URL as default so that URL parsing works for relative URLs as well. We care about searchParams and pathname only
const parsedUrl = new URL(asPath, "https://dummyurl");
const isEmbed = parsedUrl.pathname.endsWith("/embed") || parsedUrl.searchParams.get("embedType") !== null;
const isEmbedSnippetGeneratorPath = parsedUrl.pathname.startsWith("/event-types");
// FIXME: Revisit this logic to remove embedType query param check completely. Ideally, /embed should always be there at the end of the URL. Test properly and then remove it.
const isEmbed =
(parsedUrl.pathname.endsWith("/embed") || parsedUrl.searchParams.get("embedType") !== null) &&
!isEmbedSnippetGeneratorPath;
const embedColorScheme = parsedUrl.searchParams.get("ui.color-scheme");
const initialProps = await Document.getInitialProps(ctx);
return { isEmbed, embedColorScheme, nonce, ...initialProps };

View File

@ -82,12 +82,6 @@ function useRouterHelpers() {
return { goto, removeQueryParams };
}
const getQueryParam = (queryParam: string) => {
const params = new URLSearchParams(window.location.search);
return params.get(queryParam);
};
const ThemeSelectControl = ({ children, ...props }: ControlProps<{ value: Theme; label: string }, false>) => {
return (
<components.Control {...props}>
@ -526,7 +520,7 @@ const EmbedTypeCodeAndPreviewDialogContent = ({
(state) => [state.month, state.selectedDatesAndTimes],
shallow
);
const eventId = getQueryParam("eventId");
const eventId = searchParams.get("eventId");
const calLink = decodeURIComponent(embedUrl);
const { data: eventTypeData } = trpc.viewer.eventTypes.get.useQuery(
{ id: parseInt(eventId as string) },