Skip to content

Commit

Permalink
feat: onBeforeRenderClient() (closes #110) (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
crisberrios authored May 6, 2024
1 parent b336907 commit 68be831
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions packages/vike-react/src/+config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ export default {
_streamIsRequied: {
env: { server: true }
},
onBeforeRenderClient: {
env: { client: true }
},
onAfterRenderClient: {
env: { client: true }
},
Expand Down
2 changes: 2 additions & 0 deletions packages/vike-react/src/renderer/onRenderClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import { getPageElement } from './getPageElement.js'

let root: ReactDOM.Root
const onRenderClient: OnRenderClientSync = (pageContext): ReturnType<OnRenderClientSync> => {
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.
Expand Down
7 changes: 7 additions & 0 deletions packages/vike-react/src/types/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 68be831

Please sign in to comment.