Skip to content

Commit

Permalink
fix(runtime): 修复使用 recoil 报错的问题,fix #10119
Browse files Browse the repository at this point in the history
封装 window.setTimeout、window.clearTimeout,避免第三方库使用 window.setTimeout 调用时,Taro 封装的 window 对象和真正挂载 setTimeout 的 global 对象不一样时,报 Illegal invocation 的问题
  • Loading branch information
Chen-jj committed Nov 22, 2021
1 parent 1a6728b commit 0e140c4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions packages/taro-runtime/src/bom/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { document } from './document'
import { isBrowser, win } from '../env'
import { raf, caf } from './raf'
import { getComputedStyle } from './getComputedStyle'
import { DATE, SET_TIMEOUT } from '../constants'
import { DATE } from '../constants'

export const window = isBrowser ? win : {
navigator,
Expand Down Expand Up @@ -35,7 +35,10 @@ if (process.env.TARO_ENV && process.env.TARO_ENV !== 'h5') {
if (!(DATE in window)) {
(window as any).Date = Date
}
if (!(SET_TIMEOUT in window)) {
(window as any).setTimeout = setTimeout
(window as any).setTimeout = function (cb, delay) {
setTimeout(cb, delay)
}
;(window as any).clearTimeout = function (seed) {
clearTimeout(seed)
}
}

0 comments on commit 0e140c4

Please sign in to comment.