فهرست منبع

fix(shared): toNumber should only coerce strings

Evan You 3 سال پیش
والد
کامیت
b55846f05c
2فایلهای تغییر یافته به همراه3 افزوده شده و 2 حذف شده
  1. 1 1
      packages/runtime-core/src/components/Suspense.ts
  2. 2 1
      packages/shared/src/index.ts

+ 1 - 1
packages/runtime-core/src/components/Suspense.ts

@@ -423,7 +423,7 @@ function createSuspenseBoundary(
     o: { parentNode, remove }
   } = rendererInternals
 
-  const timeout = toNumber(vnode.props && vnode.props.timeout)
+  const timeout = vnode.props ? toNumber(vnode.props.timeout) : undefined
   if (__DEV__) {
     assertNumber(timeout, `Suspense timeout`)
   }

+ 2 - 1
packages/shared/src/index.ts

@@ -163,10 +163,11 @@ export const looseToNumber = (val: any): any => {
 }
 
 /**
+ * Only conerces number-like strings
  * "123-foo" will be returned as-is
  */
 export const toNumber = (val: any): any => {
-  const n = Number(val)
+  const n = isString(val) ? Number(val) : NaN
   return isNaN(n) ? val : n
 }