From e5eca75f400a3e84ee6095cf7c88f0c3888f82b7 Mon Sep 17 00:00:00 2001 From: Tim Neutkens Date: Mon, 14 Nov 2022 10:57:17 +0100 Subject: [PATCH] Use window.location directly instead of parsing into URL Fixes https://github.com/vercel/next.js/pull/42735#discussion_r1019116319. --- packages/next/client/components/app-router.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/next/client/components/app-router.tsx b/packages/next/client/components/app-router.tsx index 634c4ee55a535c2..45ba34e430f0c27 100644 --- a/packages/next/client/components/app-router.tsx +++ b/packages/next/client/components/app-router.tsx @@ -136,7 +136,8 @@ function Router({ // location.href is read as the initial value for canonicalUrl in the browser // This is safe to do as canonicalUrl can't be rendered, it's only used to control the history updates in the useEffect further down in this file. typeof window !== 'undefined' - ? createHrefFromUrl(new URL(window.location.href)) + ? // window.location does not have the same type as URL but has all the fields createHrefFromUrl needs. + createHrefFromUrl(window.location as unknown as URL) : initialCanonicalUrl, } }, [children, initialCanonicalUrl, initialTree])