Просмотр исходного кода

refactor(runtime-vapor): share logMismatchError with runtime-core

daiwei 3 дней назад
Родитель
Сommit
6667d6bda4

+ 1 - 1
packages/runtime-core/src/hydration.ts

@@ -79,7 +79,7 @@ export enum DOMNodeTypes {
 }
 
 let hasLoggedMismatchError = false
-const logMismatchError = () => {
+export const logMismatchError = (): void => {
   if (__TEST__ || hasLoggedMismatchError) {
     return
   }

+ 1 - 0
packages/runtime-core/src/index.ts

@@ -663,6 +663,7 @@ export {
   isValidHtmlOrSvgAttribute,
   getAttributeMismatch,
   isHydrating,
+  logMismatchError,
 } from './hydration'
 /**
  * @internal

+ 1 - 1
packages/runtime-vapor/src/components/Teleport.ts

@@ -10,6 +10,7 @@ import {
   isMismatchAllowed,
   isTeleportDeferred,
   isTeleportDisabled,
+  logMismatchError,
   queuePostFlushCb,
   resolveTeleportTarget,
   setCurrentInstance,
@@ -36,7 +37,6 @@ import {
   currentHydrationNode,
   isComment,
   isHydrating,
-  logMismatchError,
   markHydrationAnchor,
   runWithoutHydration,
   setCurrentHydrationNode,

+ 2 - 1
packages/runtime-vapor/src/directives/vShow.ts

@@ -1,6 +1,7 @@
 import {
   MismatchTypes,
   type VShowElement,
+  logMismatchError,
   vShowHidden,
   vShowOriginalDisplay,
   warn,
@@ -10,7 +11,7 @@ import { renderEffect } from '../renderEffect'
 import { isVaporComponent } from '../component'
 import type { Block, TransitionBlock } from '../block'
 import { isArray } from '@vue/shared'
-import { isHydrating, logMismatchError } from '../dom/hydration'
+import { isHydrating } from '../dom/hydration'
 import { isDynamicFragment, isFragment } from '../fragment'
 
 export interface PendingVShow {

+ 1 - 10
packages/runtime-vapor/src/dom/hydration.ts

@@ -2,6 +2,7 @@ import {
   MismatchTypes,
   isMismatchAllowed,
   isHydrating as isVdomHydrating,
+  logMismatchError,
   warn,
 } from '@vue/runtime-dom'
 import { type Namespace, Namespaces } from '@vue/shared'
@@ -483,16 +484,6 @@ function warnHydrationNodeMismatch(node: Node, expected: unknown): void {
   }
 }
 
-let hasLoggedMismatchError = false
-export const logMismatchError = (): void => {
-  if (__TEST__ || hasLoggedMismatchError) {
-    return
-  }
-  // this error should show up in production
-  console.error('Hydration completed but contains mismatches.')
-  hasLoggedMismatchError = true
-}
-
 export function removeFragmentNodes(node: Node, endAnchor?: Node): void {
   const parent = parentNode(node)
   if (!parent) {

+ 1 - 1
packages/runtime-vapor/src/dom/prop.ts

@@ -24,6 +24,7 @@ import {
   isMismatchAllowed,
   isSetEqual,
   isValidHtmlOrSvgAttribute,
+  logMismatchError,
   mergeProps,
   patchStyle,
   queuePostFlushCb,
@@ -45,7 +46,6 @@ import {
 import {
   isHydrating,
   isRecreatedNode,
-  logMismatchError,
   warnHydrationTextMismatch,
 } from './hydration'
 import { type Block, normalizeBlock } from '../block'