vike-ripple 0.4.4 → 0.4.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
export { onRenderClient }
|
|
2
2
|
|
|
3
|
-
import { hydrate } from 'ripple'
|
|
4
3
|
import { setPageContext } from '../hooks/usePageContext.js'
|
|
5
4
|
import { setHydrated } from '../hooks/useHydrated.js'
|
|
6
5
|
|
|
7
|
-
let hydrated = false
|
|
8
|
-
|
|
9
6
|
const onRenderClient = async (pageContext) => {
|
|
10
7
|
const { Page } = pageContext
|
|
11
8
|
if (!Page) return
|
|
@@ -14,24 +11,8 @@ const onRenderClient = async (pageContext) => {
|
|
|
14
11
|
const container = document.getElementById('root')
|
|
15
12
|
if (!container) return
|
|
16
13
|
|
|
17
|
-
//
|
|
18
|
-
if (pageContext.isHydration && container.innerHTML !== '' && !hydrated) {
|
|
19
|
-
try {
|
|
20
|
-
hydrate(Page, { target: container, props: {} })
|
|
21
|
-
hydrated = true
|
|
22
|
-
setHydrated()
|
|
23
|
-
return
|
|
24
|
-
} catch (err) {
|
|
25
|
-
console.warn('[vike-ripple] hydrate failed, falling back to mount:', err)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Mount — initial load (if hydrate failed) AND HMR / client navigation
|
|
14
|
+
// mount() clears container (target.textContent = '') and renders fresh
|
|
30
15
|
const { mount } = await import('ripple')
|
|
31
|
-
// Clear container before mount to prevent duplicate content
|
|
32
|
-
// (during HMR the old content is still in the DOM)
|
|
33
|
-
if (!pageContext.isHydration) container.innerHTML = ''
|
|
34
16
|
mount(Page, { target: container, props: {} })
|
|
35
|
-
hydrated = true
|
|
36
17
|
setHydrated()
|
|
37
18
|
}
|