Skip to content

Commit

Permalink
Add onAfterRenderClient
Browse files Browse the repository at this point in the history
  • Loading branch information
ivangreene committed Mar 11, 2024
1 parent b59df26 commit 033ce5e
Show file tree
Hide file tree
Showing 4 changed files with 21 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 @@ -47,6 +47,9 @@ export default {
stream: {
env: { server: true }
},
onAfterRenderClient: {
env: { client: true }
},
VikeReactQueryWrapper: {
env: { client: true, server: true }
},
Expand Down
5 changes: 5 additions & 0 deletions packages/vike-react/src/renderer/onRenderClient.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ const onRenderClient: OnRenderClientSync = (pageContext): ReturnType<OnRenderCli

root.render(page)
}
pageContext.page = page
pageContext.root = root
if (pageContext.config.onAfterRenderClient) {
pageContext.config.onAfterRenderClient(pageContext)
}
}

// https://stackoverflow.com/questions/260857/changing-website-favicon-dynamically/260876#260876
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
@@ -1,4 +1,6 @@
// https://vike.dev/meta#typescript
import type { PageContextClient } from 'vike/types'

declare global {
// As a Vike user, use Vike.Config instead of VikePackages.ConfigVikeReact (see https://vike.dev/meta#typescript)
namespace VikePackages {
Expand Down Expand Up @@ -38,6 +40,11 @@ declare global {
*
*/
stream?: boolean
/**
* If present, called after the page is rendered on the client. The `page` and `root`
* properties will be populated.
*/
onAfterRenderClient?: (pageContext: PageContextClient) => void

VikeReactQueryWrapper?: React.ReactNode

Expand Down
6 changes: 6 additions & 0 deletions packages/vike-react/src/types/PageContext.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
// https://vike.dev/pageContext#typescript
import type React from 'react'
import type { JSX } from 'react'
import type ReactDOM from 'react-dom/client'

declare global {
namespace Vike {
interface PageContext {
Page?: () => React.ReactNode
userAgent?: string
page?: JSX.Element
root?: ReactDOM.Root
}
}
}

0 comments on commit 033ce5e

Please sign in to comment.