Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: onBeforeRenderClient() (closes #110) #111

Merged
merged 3 commits into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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