Skip to content
Source
Sign inSign up
TanStack/router

fix(vue-router): keep the Body root after hydration #8816

Openpyyupsk(GitHub profile, opens in a new tab)wants to merge 5 commits intomain fromrefs/pull/8816/headopened

Showing 3 changed files with 109 additions and 7 deletions.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/vue-html-keep-root.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/vue-router': patch
+---
+​
+After hydration, `Html` keeps `Body` as the root vnode and renders the head teleport inside it. Components on the page mount once, and CSS animations no longer start again.
15 additions and 7 deletionspackages/vue-router/src/Html.tsxModified
View file
@@ -49,17 +49,25 @@
​
- const result: Array<Vue.VNode> = []
-​
- if (bodyVnode) {
- result.push(bodyVnode)
+ if (!hydrated.value || headChildren.length === 0) {
+ return bodyVnode
​
- if (hydrated.value && headChildren.length > 0) {
- result.push(Vue.h(Vue.Teleport, { to: 'head' }, headChildren))
+ const head = Vue.h(Vue.Teleport, { to: 'head' }, headChildren)
+ if (bodyVnode?.type !== Body) {
+ return Vue.h(Vue.Fragment, [bodyVnode, head])
​
- return result.length === 1 ? result[0] : Vue.h(Vue.Fragment, result)
+ const bodyChildren = bodyVnode.children
+ const content = Array.isArray(bodyChildren)