Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
fix(shared): toNumber should only coerce strings
  • Loading branch information
yyx990803 committed Nov 14, 2022
1 parent eb2a832 commit b55846f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/runtime-core/src/components/Suspense.ts
Expand Up @@ -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`)
}
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/src/index.ts
Expand Up @@ -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
}

Expand Down

0 comments on commit b55846f

Please sign in to comment.