Explorar el Código

fix(shared): toNumber should only coerce strings

Evan You hace 3 años
padre
commit
b55846f05c

+ 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
 }