diff --git a/packages/vike-react/src/+config.ts b/packages/vike-react/src/+config.ts index 2b1a3de4..d073f9b7 100644 --- a/packages/vike-react/src/+config.ts +++ b/packages/vike-react/src/+config.ts @@ -49,6 +49,9 @@ export default { _streamIsRequied: { env: { server: true } }, + onBeforeRenderClient: { + env: { client: true } + }, onAfterRenderClient: { env: { client: true } }, diff --git a/packages/vike-react/src/renderer/onRenderClient.tsx b/packages/vike-react/src/renderer/onRenderClient.tsx index fbee996b..d5cc63c0 100644 --- a/packages/vike-react/src/renderer/onRenderClient.tsx +++ b/packages/vike-react/src/renderer/onRenderClient.tsx @@ -8,6 +8,8 @@ import { getPageElement } from './getPageElement.js' let root: ReactDOM.Root const onRenderClient: OnRenderClientSync = (pageContext): ReturnType => { + pageContext.config.onBeforeRenderClient?.(pageContext) + const page = getPageElement(pageContext) // TODO: implement this? So that, upon errors, onRenderClient() throws an error and Vike can render the error. As of April 2024 it isn't released yet. diff --git a/packages/vike-react/src/types/Config.ts b/packages/vike-react/src/types/Config.ts index e2736e0d..4b126c6c 100644 --- a/packages/vike-react/src/types/Config.ts +++ b/packages/vike-react/src/types/Config.ts @@ -58,6 +58,13 @@ declare global { * */ stream?: boolean + /** + * Client-side hook called before the page is rendered. + */ + + // https://github.com/vikejs/vike-react/issues/110 + onBeforeRenderClient?: (pageContext: PageContextClient) => void + /** * Client-side hook called after the page is rendered. */