diff --git a/code/frameworks/nextjs/template/next-env.d.ts b/code/frameworks/nextjs/template/next-env.d.ts new file mode 100644 index 000000000000..77e567dab0a2 --- /dev/null +++ b/code/frameworks/nextjs/template/next-env.d.ts @@ -0,0 +1,7 @@ +// Reference necessary since Next.js 13.2.0, because types in `next/navigation` are not exported per default, but +// type references are dynamically created during Next.js start up. +// See https://github.com/vercel/next.js/commit/cdf1d52d9aed42d01a46539886a4bda14cb77a99 +// for more insights. + +/// +/// diff --git a/code/frameworks/nextjs/template/stories_default-js/Navigation.stories.jsx b/code/frameworks/nextjs/template/stories_default-js/Navigation.stories.jsx index f43167da2c14..12b66e3205d2 100644 --- a/code/frameworks/nextjs/template/stories_default-js/Navigation.stories.jsx +++ b/code/frameworks/nextjs/template/stories_default-js/Navigation.stories.jsx @@ -14,7 +14,7 @@ function Component() { const segment = useSelectedLayoutSegment(); const segments = useSelectedLayoutSegments(); - const searchParamsList = Array.from(searchParams.entries()); + const searchParamsList = searchParams ? Array.from(searchParams.entries()) : []; const routerActions = [ { diff --git a/code/frameworks/nextjs/template/stories_default-ts/Navigation.stories.tsx b/code/frameworks/nextjs/template/stories_default-ts/Navigation.stories.tsx index a4c2f2d27758..8bb209bd9d45 100644 --- a/code/frameworks/nextjs/template/stories_default-ts/Navigation.stories.tsx +++ b/code/frameworks/nextjs/template/stories_default-ts/Navigation.stories.tsx @@ -1,3 +1,4 @@ +// usePathname and useSearchParams are only usable if experimental: {appDir: true} is set in next.config.js import { useRouter, usePathname, useSearchParams } from 'next/navigation'; import React from 'react'; import type { Meta, StoryObj } from '@storybook/react'; @@ -7,7 +8,7 @@ function Component() { const pathname = usePathname(); const searchParams = useSearchParams(); - const searchParamsList = Array.from(searchParams.entries()); + const searchParamsList = searchParams ? Array.from(searchParams.entries()) : []; const routerActions = [ {