vike-ripple 0.4.2 → 0.4.4
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
|
@@ -4,7 +4,7 @@ import { hydrate } from 'ripple'
|
|
|
4
4
|
import { setPageContext } from '../hooks/usePageContext.js'
|
|
5
5
|
import { setHydrated } from '../hooks/useHydrated.js'
|
|
6
6
|
|
|
7
|
-
let
|
|
7
|
+
let hydrated = false
|
|
8
8
|
|
|
9
9
|
const onRenderClient = async (pageContext) => {
|
|
10
10
|
const { Page } = pageContext
|
|
@@ -14,20 +14,24 @@ const onRenderClient = async (pageContext) => {
|
|
|
14
14
|
const container = document.getElementById('root')
|
|
15
15
|
if (!container) return
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
// Hydration — only on the very first page load (SSR)
|
|
18
|
+
if (pageContext.isHydration && container.innerHTML !== '' && !hydrated) {
|
|
18
19
|
try {
|
|
19
20
|
hydrate(Page, { target: container, props: {} })
|
|
20
|
-
|
|
21
|
+
hydrated = true
|
|
21
22
|
setHydrated()
|
|
23
|
+
return
|
|
22
24
|
} catch (err) {
|
|
23
25
|
console.warn('[vike-ripple] hydrate failed, falling back to mount:', err)
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
|
|
27
|
-
if
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
29
|
+
// Mount — initial load (if hydrate failed) AND HMR / client navigation
|
|
30
|
+
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
|
+
mount(Page, { target: container, props: {} })
|
|
35
|
+
hydrated = true
|
|
36
|
+
setHydrated()
|
|
33
37
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export { onRenderHtml }
|
|
2
2
|
|
|
3
3
|
import { render, create_ssr_stream } from 'ripple/server'
|
|
4
|
+
import { tsrx_element } from 'ripple/internal/server'
|
|
4
5
|
import { escapeInject, dangerouslySkipEscape } from 'vike/server'
|
|
5
6
|
import { setPageContext } from '../hooks/usePageContext.js'
|
|
6
7
|
import { getHeadSetting } from './getHeadSetting.js'
|
|
@@ -28,14 +29,14 @@ const onRenderHtml = async (pageContext) => {
|
|
|
28
29
|
for (let i = layouts.length - 1; i >= 0; i--) {
|
|
29
30
|
const L = layouts[i]
|
|
30
31
|
const prev = wrappedPage
|
|
31
|
-
wrappedPage = (props) => L({ ...props, children: prev })
|
|
32
|
+
wrappedPage = (props) => L({ ...props, children: tsrx_element(prev) })
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
if (Wrapper) {
|
|
35
36
|
const wrappers = Array.isArray(Wrapper) ? Wrapper : [Wrapper]
|
|
36
37
|
for (const W of wrappers) {
|
|
37
38
|
const prev = wrappedPage
|
|
38
|
-
wrappedPage = (props) => W({ ...props, children: prev })
|
|
39
|
+
wrappedPage = (props) => W({ ...props, children: tsrx_element(prev) })
|
|
39
40
|
}
|
|
40
41
|
}
|
|
41
42
|
|