= ({
- ssrState,
- csrResult,
+ staticState,
+ hydratedState,
}) => (
<>
@@ -17,12 +17,15 @@ export const HydrationMetadata: FunctionComponent = ({
id="hydrated-indicator"
type="checkbox"
disabled
- checked={!!csrResult}
+ checked={!!hydratedState}
/>
Rendered page with{' '}
- {(csrResult ?? ssrState).controllers.resultList.state.results.length}{' '}
+ {
+ (hydratedState ?? staticState).controllers.resultList.state.results
+ .length
+ }{' '}
results
diff --git a/packages/samples/headless-ssr/src/app/generic/common/engine.ts b/packages/samples/headless-ssr/src/app/generic/common/engine.ts
index 8e6b7f25890..3774214dc71 100644
--- a/packages/samples/headless-ssr/src/app/generic/common/engine.ts
+++ b/packages/samples/headless-ssr/src/app/generic/common/engine.ts
@@ -1,13 +1,13 @@
import {
defineSearchEngine,
- InferSSRState,
- InferCSRState,
+ InferStaticState,
+ InferHydratedState,
} from '@coveo/headless/ssr';
import {config} from '../../common/search-engine-config';
const engineDefinition = defineSearchEngine(config);
-export type SearchSSRState = InferSSRState;
-export type SearchCSRState = InferCSRState;
+export type SearchStaticState = InferStaticState;
+export type SearchHydratedState = InferHydratedState;
-export const {fetchInitialState, hydrateInitialState} = engineDefinition;
+export const {fetchStaticState, hydrateStaticState} = engineDefinition;
diff --git a/packages/samples/headless-ssr/src/app/generic/components/result-list.tsx b/packages/samples/headless-ssr/src/app/generic/components/result-list.tsx
index 53a91525e68..4c8ff505eb4 100644
--- a/packages/samples/headless-ssr/src/app/generic/components/result-list.tsx
+++ b/packages/samples/headless-ssr/src/app/generic/components/result-list.tsx
@@ -6,15 +6,15 @@ import {useEffect, useState, FunctionComponent} from 'react';
import ResultListCommon from '../../common/result-list';
interface ResultListProps {
- ssrState: ResultListState;
+ staticState: ResultListState;
controller?: ResultListController;
}
export const ResultList: FunctionComponent = ({
- ssrState,
+ staticState,
controller,
}) => {
- const [state, setState] = useState(ssrState);
+ const [state, setState] = useState(staticState);
useEffect(
() => controller?.subscribe(() => setState({...controller.state})),
diff --git a/packages/samples/headless-ssr/src/app/generic/components/search-box.tsx b/packages/samples/headless-ssr/src/app/generic/components/search-box.tsx
index dc75e606d38..7484ff94a74 100644
--- a/packages/samples/headless-ssr/src/app/generic/components/search-box.tsx
+++ b/packages/samples/headless-ssr/src/app/generic/components/search-box.tsx
@@ -6,15 +6,15 @@ import {useEffect, useState, FunctionComponent} from 'react';
import SearchBoxCommon from '../../common/search-box';
interface SearchBoxProps {
- ssrState: SearchBoxState;
+ staticState: SearchBoxState;
controller?: SearchBoxController;
}
export const SearchBox: FunctionComponent = ({
- ssrState,
+ staticState,
controller,
}: SearchBoxProps) => {
- const [state, setState] = useState(ssrState);
+ const [state, setState] = useState(staticState);
useEffect(
() => controller?.subscribe?.(() => setState({...controller.state})),
diff --git a/packages/samples/headless-ssr/src/app/generic/components/search-page.tsx b/packages/samples/headless-ssr/src/app/generic/components/search-page.tsx
index 534c75437ac..42036080989 100644
--- a/packages/samples/headless-ssr/src/app/generic/components/search-page.tsx
+++ b/packages/samples/headless-ssr/src/app/generic/components/search-page.tsx
@@ -1,9 +1,9 @@
'use client';
import {
- SearchSSRState,
- SearchCSRState,
- hydrateInitialState,
+ SearchStaticState,
+ SearchHydratedState,
+ hydrateStaticState,
} from '@/src/app/generic/common/engine';
import {useEffect, useState} from 'react';
import {HydrationMetadata} from '../../common/hydration-metadata';
@@ -11,40 +11,47 @@ import {useSyncSearchParameters} from '../hooks/search-parameters';
import {ResultList} from './result-list';
import {SearchBox} from './search-box';
-export default function SearchPage({ssrState}: {ssrState: SearchSSRState}) {
- const [csrResult, setCSRResult] = useState(
- undefined
- );
+export default function SearchPage({
+ staticState,
+}: {
+ staticState: SearchStaticState;
+}) {
+ const [hydratedState, setHydratedState] = useState<
+ SearchHydratedState | undefined
+ >(undefined);
useEffect(() => {
- hydrateInitialState({
- searchFulfilledAction: ssrState.searchFulfilledAction,
+ hydrateStaticState({
+ searchFulfilledAction: staticState.searchFulfilledAction,
controllers: {
searchParameters: {
- initialState: ssrState.controllers.searchParameters.state,
+ initialState: staticState.controllers.searchParameters.state,
},
},
}).then(({engine, controllers}) => {
- setCSRResult({engine, controllers});
+ setHydratedState({engine, controllers});
});
- }, [ssrState]);
+ }, [staticState]);
useSyncSearchParameters({
- ssrState: ssrState.controllers.searchParameters.state,
- controller: csrResult?.controllers.searchParameters,
+ staticState: staticState.controllers.searchParameters.state,
+ controller: hydratedState?.controllers.searchParameters,
});
return (
<>
+
-
>
);
}
diff --git a/packages/samples/headless-ssr/src/app/generic/hooks/search-parameters.ts b/packages/samples/headless-ssr/src/app/generic/hooks/search-parameters.ts
index 09acf70fe89..60545adf65d 100644
--- a/packages/samples/headless-ssr/src/app/generic/hooks/search-parameters.ts
+++ b/packages/samples/headless-ssr/src/app/generic/hooks/search-parameters.ts
@@ -9,15 +9,15 @@ import {useHistoryRouter} from '../../common/search-parameters';
import {CoveoNextJsSearchParametersSerializer} from '../../common/search-parameters-serializer';
interface UseSyncSearchParametersProps {
- ssrState: SearchParameterManagerState;
+ staticState: SearchParameterManagerState;
controller?: SearchParameterManager;
}
function useSearchParameters({
- ssrState,
+ staticState,
controller,
}: UseSyncSearchParametersProps) {
- const [searchParameters, setSearchParameters] = useState(ssrState);
+ const [searchParameters, setSearchParameters] = useState(staticState);
useEffect(() => {
if (!controller) {
return;
@@ -28,11 +28,11 @@ function useSearchParameters({
}
export function useSyncSearchParameters({
- ssrState,
+ staticState,
controller,
}: UseSyncSearchParametersProps) {
const historyRouter = useHistoryRouter();
- const state = useSearchParameters({ssrState, controller});
+ const state = useSearchParameters({staticState, controller});
// Update the search interface.
useEffect(
@@ -63,8 +63,8 @@ export function useSyncSearchParameters({
if (!correctedUrl || correctedUrl === historyRouter.url?.href) {
return;
}
- const isInitialState = controller === undefined;
- if (isInitialState) {
+ const isStaticState = controller === undefined;
+ if (isStaticState) {
historyRouter.replace(correctedUrl);
} else {
historyRouter.push(correctedUrl);
diff --git a/packages/samples/headless-ssr/src/app/generic/page.tsx b/packages/samples/headless-ssr/src/app/generic/page.tsx
index b3b83bb3401..970125f3733 100644
--- a/packages/samples/headless-ssr/src/app/generic/page.tsx
+++ b/packages/samples/headless-ssr/src/app/generic/page.tsx
@@ -2,7 +2,7 @@ import {
CoveoNextJsSearchParametersSerializer,
NextJSServerSideSearchParams,
} from '@/src/app/common/search-parameters-serializer';
-import {fetchInitialState} from '@/src/app/generic/common/engine';
+import {fetchStaticState} from '@/src/app/generic/common/engine';
import SearchPage from '@/src/app/generic/components/search-page';
// Entry point SSR function
@@ -13,7 +13,7 @@ export default async function Search(url: {
CoveoNextJsSearchParametersSerializer.fromServerSideUrlSearchParams(
url.searchParams
);
- const ssrState = await fetchInitialState({
+ const staticState = await fetchStaticState({
controllers: {
searchParameters: {
initialState: {
@@ -22,7 +22,7 @@ export default async function Search(url: {
},
},
});
- return ;
+ return ;
}
// A page with search parameters cannot be statically rendered, since its rendered state should look different based on the current search parameters.
diff --git a/packages/samples/headless-ssr/src/app/react/common/engine.ts b/packages/samples/headless-ssr/src/app/react/common/engine.ts
index c75265f2e0c..a7936a8b288 100644
--- a/packages/samples/headless-ssr/src/app/react/common/engine.ts
+++ b/packages/samples/headless-ssr/src/app/react/common/engine.ts
@@ -1,17 +1,17 @@
import {defineSearchEngine} from '@coveo/headless-react';
-import {InferSSRState, InferCSRState} from '@coveo/headless/ssr';
+import {InferStaticState, InferHydratedState} from '@coveo/headless/ssr';
import {config} from '../../common/search-engine-config';
const engineDefinition = defineSearchEngine(config);
-export type SearchSSRState = InferSSRState;
-export type SearchCSRState = InferCSRState;
+export type SearchStaticState = InferStaticState;
+export type SearchHydratedState = InferHydratedState;
export const {
- fetchInitialState,
- hydrateInitialState,
- SSRStateProvider,
- CSRProvider,
+ fetchStaticState,
+ hydrateStaticState,
+ StaticStateProvider,
+ HydratedStateProvider,
} = engineDefinition;
export const {useResultList, useSearchBox, useSearchParameters} =
diff --git a/packages/samples/headless-ssr/src/app/react/components/search-page.tsx b/packages/samples/headless-ssr/src/app/react/components/search-page.tsx
index fb59801ef22..6072d01ee20 100644
--- a/packages/samples/headless-ssr/src/app/react/components/search-page.tsx
+++ b/packages/samples/headless-ssr/src/app/react/components/search-page.tsx
@@ -1,56 +1,62 @@
'use client';
import {
- SearchSSRState,
- SearchCSRState,
- hydrateInitialState,
- CSRProvider,
- SSRStateProvider,
+ SearchStaticState,
+ SearchHydratedState,
+ hydrateStaticState,
+ HydratedStateProvider,
+ StaticStateProvider,
} from '@/src/app/react/common/engine';
import {useEffect, useState, PropsWithChildren} from 'react';
import {HydrationMetadata} from '../../common/hydration-metadata';
interface SearchPageProviderProps {
- ssrState: SearchSSRState;
+ staticState: SearchStaticState;
}
export function SearchPageProvider({
- ssrState,
+ staticState,
children,
}: PropsWithChildren) {
- const [csrResult, setCSRResult] = useState(
- undefined
- );
+ const [hydratedState, setHydratedState] = useState<
+ SearchHydratedState | undefined
+ >(undefined);
useEffect(() => {
- hydrateInitialState({
- searchFulfilledAction: ssrState.searchFulfilledAction,
+ hydrateStaticState({
+ searchFulfilledAction: staticState.searchFulfilledAction,
controllers: {
searchParameters: {
- initialState: ssrState.controllers.searchParameters.state,
+ initialState: staticState.controllers.searchParameters.state,
},
},
}).then(({engine, controllers}) => {
- setCSRResult({engine, controllers});
+ setHydratedState({engine, controllers});
});
- }, [ssrState]);
+ }, [staticState]);
- if (csrResult) {
+ if (hydratedState) {
return (
-
{children}
-
-
+
+
);
} else {
return (
-
+
{children}
-
-
+
+
);
}
}
diff --git a/packages/samples/headless-ssr/src/app/react/components/search-parameters.tsx b/packages/samples/headless-ssr/src/app/react/components/search-parameters.tsx
index ab831de7a4b..d4d094c51df 100644
--- a/packages/samples/headless-ssr/src/app/react/components/search-parameters.tsx
+++ b/packages/samples/headless-ssr/src/app/react/components/search-parameters.tsx
@@ -38,8 +38,8 @@ export default function SearchParameters() {
if (!correctedUrl || correctedUrl === historyRouter.url?.href) {
return;
}
- const isInitialState = methods === undefined;
- if (isInitialState) {
+ const isStaticState = methods === undefined;
+ if (isStaticState) {
historyRouter.replace(correctedUrl);
} else {
historyRouter.push(correctedUrl);
diff --git a/packages/samples/headless-ssr/src/app/react/page.tsx b/packages/samples/headless-ssr/src/app/react/page.tsx
index 1eb454dfe2f..df8deb8ef6a 100644
--- a/packages/samples/headless-ssr/src/app/react/page.tsx
+++ b/packages/samples/headless-ssr/src/app/react/page.tsx
@@ -1,4 +1,4 @@
-import {fetchInitialState} from '@/src/app/react/common/engine';
+import {fetchStaticState} from '@/src/app/react/common/engine';
import {SearchPageProvider} from '@/src/app/react/components/search-page';
import {
CoveoNextJsSearchParametersSerializer,
@@ -16,7 +16,7 @@ export default async function Search(url: {
CoveoNextJsSearchParametersSerializer.fromServerSideUrlSearchParams(
url.searchParams
);
- const ssrState = await fetchInitialState({
+ const staticState = await fetchStaticState({
controllers: {
searchParameters: {
initialState: {
@@ -27,7 +27,7 @@ export default async function Search(url: {
});
return (
-
+