File tree Expand file tree Collapse file tree 1 file changed +25
-2
lines changed
Expand file tree Collapse file tree 1 file changed +25
-2
lines changed Original file line number Diff line number Diff line change 11"use client" ;
22
33import { useRouter } from "next/navigation" ;
4- import { type FunctionComponent , useState } from "react" ;
4+ import { type FunctionComponent , useEffect , useState } from "react" ;
55import { useBoolean } from "react-use" ;
66import Stack from "^/components/ui/Stack" ;
77import { type AutocompleteSuggestion } from "^/lib/autocomplete" ;
@@ -76,4 +76,27 @@ const IndexPageClient: FunctionComponent<LandingProps> = ({
7676 ) ;
7777} ;
7878
79- export default IndexPageClient ;
79+ // Wrapper to reset state on unmount
80+ // This is to handle nexjts stupid assumption with cacheComponents
81+ // that all pages are wrapped in <Activity> which maintains state across navigations
82+ // See:
83+ // https://nextjs.org/docs/app/getting-started/cache-components#navigation-uses-activity
84+ // https://github.com/vercel/next.js/discussions/85502
85+ // https://github.com/vercel/next.js/issues/86577
86+ const IndexPageClientWrapper : FunctionComponent < LandingProps > = ( {
87+ fallbackSuggestions,
88+ } ) => {
89+ const [ key , setKey ] = useState ( 0 ) ;
90+
91+ useEffect ( ( ) => {
92+ return function onUnmount ( ) {
93+ setKey ( ( prev ) => prev + 1 ) ;
94+ } ;
95+ } , [ ] ) ;
96+
97+ return (
98+ < IndexPageClient fallbackSuggestions = { fallbackSuggestions } key = { key } />
99+ ) ;
100+ } ;
101+
102+ export default IndexPageClientWrapper ;
You can’t perform that action at this time.
0 commit comments