mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1// @ts-ignore no decl -prf
2import * as findLast from 'array.prototype.findlast'
3/// <reference lib="dom" />
4
5findLast.shim()
6
7// @ts-ignore whatever typescript wants to complain about here, I dont care about -prf
8window.setImmediate = (cb: () => void) => setTimeout(cb, 0)
9
10if (process.env.NODE_ENV !== 'production') {
11 // In development, react-native-web's <View> tries to validate that
12 // text is wrapped into <Text>. It doesn't catch all cases but is useful.
13 // Unfortunately, it only does that via console.error so it's easy to miss.
14 // This is a hack to get it showing as a redbox on the web so we catch it early.
15 const realConsoleError = console.error
16 const thrownErrors = new WeakSet()
17 console.error = function consoleErrorWrapper(msgOrError) {
18 if (
19 typeof msgOrError === 'string' &&
20 msgOrError.startsWith('Unexpected text node')
21 ) {
22 if (
23 msgOrError ===
24 'Unexpected text node: . A text node cannot be a child of a <View>.'
25 ) {
26 // This is due to a stray empty string.
27 // React already handles this fine, so RNW warning is a false positive. Ignore.
28 return
29 }
30 const err = new Error(msgOrError)
31 thrownErrors.add(err)
32 throw err
33 } else if (!thrownErrors.has(msgOrError)) {
34 return realConsoleError.apply(this, arguments as any)
35 }
36 }
37}