MCPcopy
hub / github.com/vuejs/core / hydrateElement

Function hydrateElement

packages/runtime-core/src/hydration.ts:368–567  ·  view source on GitHub ↗
(
    el: Element,
    vnode: VNode,
    parentComponent: ComponentInternalInstance | null,
    parentSuspense: SuspenseBoundary | null,
    slotScopeIds: string[] | null,
    optimized: boolean,
  )

Source from the content-addressed store, hash-verified

366 }
367
368 const hydrateElement = (
369 el: Element,
370 vnode: VNode,
371 parentComponent: ComponentInternalInstance | null,
372 parentSuspense: SuspenseBoundary | null,
373 slotScopeIds: string[] | null,
374 optimized: boolean,
375 ) => {
376 optimized = optimized || !!vnode.dynamicChildren
377 const {
378 type,
379 dynamicProps,
380 props,
381 patchFlag,
382 shapeFlag,
383 dirs,
384 transition,
385 } = vnode
386 // #4006 for form elements with non-string v-model value bindings
387 // e.g. <option :value="obj">, <input type="checkbox" :true-value="1">
388 // #7476 <input indeterminate>
389 const forcePatch = type === 'input' || type === 'option'
390 // #9033 force hydrate dynamic props.
391 // Keep separate from forcePatch, which also patches value-like keys.
392 const hasDynamicProps = !!dynamicProps
393 // skip props & children if this is hoisted static nodes
394 // #5405 in dev, always hydrate children for HMR
395 if (
396 __DEV__ ||
397 forcePatch ||
398 hasDynamicProps ||
399 patchFlag !== PatchFlags.CACHED
400 ) {
401 if (dirs) {
402 invokeDirectiveHook(vnode, null, parentComponent, 'created')
403 }
404
405 // handle appear transition
406 let needCallTransitionHooks = false
407 if (isTemplateNode(el)) {
408 needCallTransitionHooks =
409 needTransition(
410 null, // no need check parentSuspense in hydration
411 transition,
412 ) &&
413 parentComponent &&
414 parentComponent.vnode.props &&
415 parentComponent.vnode.props.appear
416
417 const content = (el as HTMLTemplateElement).content
418 .firstChild as Element & { $cls?: string }
419
420 if (needCallTransitionHooks) {
421 const cls = content.getAttribute('class')
422 if (cls) content.$cls = cls
423 transition!.beforeEnter(content)
424 }
425

Callers 1

hydrateNodeFunction · 0.85

Calls 15

invokeDirectiveHookFunction · 0.90
needTransitionFunction · 0.90
warnFunction · 0.90
isOnFunction · 0.90
isReactiveFunction · 0.90
invokeVNodeHookFunction · 0.90
queueEffectWithSuspenseFunction · 0.90
hydrateChildrenFunction · 0.85
isMismatchAllowedFunction · 0.85
logMismatchErrorFunction · 0.85
propHasMismatchFunction · 0.85
beforeEnterMethod · 0.80

Tested by

no test coverage detected