Skip to content

Commit 55db5eb

Browse files
authored
fix why did you render (keybase#25352)
1 parent f5b26e6 commit 55db5eb

11 files changed

Lines changed: 124 additions & 37 deletions

File tree

‎rnmodules/react-native-drop-view/package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
"homepage": "https://github.com/keybase/client/react-native-drop-view#readme",
3131
"private": true,
3232
"devDependencies": {
33+
"@welldone-software/why-did-you-render": "7.0.1",
3334
"@types/react": "18.0.25",
3435
"@types/react-native": "0.70.6",
3536
"react-native": "0.70.5",

‎rnmodules/react-native-drop-view/yarn.lock‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,13 @@
15671567
dependencies:
15681568
"@types/yargs-parser" "*"
15691569

1570+
"@welldone-software/why-did-you-render@7.0.1":
1571+
version "7.0.1"
1572+
resolved "https://registry.yarnpkg.com/@welldone-software/why-did-you-render/-/why-did-you-render-7.0.1.tgz#09f487d84844bd8e66435843c2e0305702e61efb"
1573+
integrity sha512-Qe/8Xxa2G+LMdI6VoazescPzjjkHYduCDa8aHOJR50e9Bgs8ihkfMBY+ev7B4oc3N59Zm547Sgjf8h5y0FOyoA==
1574+
dependencies:
1575+
lodash "^4"
1576+
15701577
abort-controller@^3.0.0:
15711578
version "3.0.0"
15721579
resolved "https://registry.yarnpkg.com/abort-controller/-/abort-controller-3.0.0.tgz#eaf54d53b62bae4138e809ca225c8439a6efb392"
@@ -3349,6 +3356,11 @@ lodash.throttle@^4.1.1:
33493356
resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4"
33503357
integrity sha512-wIkUCfVKpVsWo3JSZlc+8MB5it+2AN5W8J7YVMST30UrvcQNZ1Okbj+rbVniijTWE6FGYy4XJq/rHkas8qJMLQ==
33513358

3359+
lodash@^4:
3360+
version "4.17.21"
3361+
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
3362+
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
3363+
33523364
log-symbols@^4.1.0:
33533365
version "4.1.0"
33543366
resolved "https://registry.yarnpkg.com/log-symbols/-/log-symbols-4.1.0.tgz#3fbdbb95b4683ac9fc785111e792e558d4abd503"

‎shared/babel.config.js‎

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ let isTest = null
66

77
module.exports = function (api /*: any */) {
88
const apiEnv = api.env()
9+
const isDev = apiEnv === 'development'
910

1011
if (apiEnv === 'test') {
1112
isTest = true
@@ -26,7 +27,7 @@ module.exports = function (api /*: any */) {
2627

2728
api.cache(true)
2829

29-
// console.error('KB babel.config.js ', {isElectron, isReactNative})
30+
// console.error('KB babel.config.js ', {isElectron, isReactNative, apiEnv})
3031

3132
if (!isElectron && !isReactNative) {
3233
throw new Error('MUST have env var BABEL_PLATFORM to all babel')
@@ -48,7 +49,16 @@ module.exports = function (api /*: any */) {
4849
],
4950
presets: [
5051
isTest ? ['@babel/preset-env', {targets: {node: 'current'}}] : '@babel/preset-env',
51-
'@babel/preset-react',
52+
[
53+
'@babel/preset-react',
54+
isDev
55+
? {
56+
runtime: 'automatic',
57+
development: true,
58+
importSource: '@welldone-software/why-did-you-render',
59+
}
60+
: {},
61+
],
5262
'@babel/preset-typescript',
5363
],
5464
}
@@ -58,8 +68,20 @@ module.exports = function (api /*: any */) {
5868
plugins: [
5969
...(skipAnimation ? [] : ['react-native-reanimated/plugin']),
6070
'@babel/plugin-proposal-numeric-separator',
71+
isDev
72+
? [
73+
'@babel/plugin-transform-react-jsx-development',
74+
{
75+
runtime: 'automatic',
76+
importSource: '@welldone-software/why-did-you-render',
77+
},
78+
]
79+
: ['@babel/plugin-transform-react-jsx', {runtime: 'automatic'}],
80+
],
81+
presets: [
82+
// lets us set our own jsx above
83+
['module:metro-react-native-babel-preset', {useTransformReactJSXExperimental: true}],
6184
],
62-
presets: ['module:metro-react-native-babel-preset'],
6385
}
6486
}
6587
}

‎shared/desktop/webpack.config.babel.js‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,34 @@ const config = (_, {mode}) => {
2525
plugins: [...(isHot && !nodeThread ? ['react-refresh/babel'] : [])],
2626
presets: [
2727
['@babel/preset-env', {debug: false, modules: false, targets: {electron: '19.0.4'}}],
28+
...(isDev
29+
? [
30+
[
31+
'@babel/preset-react',
32+
{
33+
runtime: 'automatic',
34+
development: isDev,
35+
importSource: '@welldone-software/why-did-you-render',
36+
},
37+
],
38+
]
39+
: []),
2840
'@babel/preset-typescript',
2941
],
3042
},
3143
}
3244

3345
return [
46+
...(isDev
47+
? []
48+
: [
49+
{
50+
// Don't include why did you render
51+
include: /welldone/,
52+
test: /\.(ts|js)x?$/,
53+
use: ['null-loader'],
54+
},
55+
]),
3456
{
3557
// Don't include large mock images in a prod build
3658
include: path.resolve(__dirname, '../images/mock'),
@@ -96,8 +118,8 @@ const config = (_, {mode}) => {
96118
'react-native-reanimated': false,
97119
}
98120
if (isDev) {
99-
// enable why did you render
100-
alias['react-redux'] = 'react-redux/dist/react-redux.js'
121+
} else {
122+
alias['@welldone-software/why-did-you-render'] = false
101123
}
102124

103125
return {

‎shared/desktop/yarn-helper/build.tsx‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const commands = {
2828
},
2929
package: {
3030
help: 'Package up the production js code',
31+
nodeEnv: 'production',
3132
shell: `yarn _node ${spaceArg} desktop/package.desktop.tsx`,
3233
},
3334
}

‎shared/index.ios.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// React-native tooling assumes this file is here, so we just require our real entry point
22
/* eslint-disable @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-argument,@typescript-eslint/no-unsafe-member-access */
3-
import 'react-native-gesture-handler' // MUST BE FIRST https://github.com/software-mansion/react-native-gesture-handler/issues/320
43
import './why-did-you-render'
4+
import 'react-native-gesture-handler' // MUST BE FIRST https://github.com/software-mansion/react-native-gesture-handler/issues/320
55
import './app/globals.native'
66
import {Appearance} from 'react-native'
77
import {darkModeSupported, guiConfig} from 'react-native-kb'
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff --git a/node_modules/@welldone-software/why-did-you-render/jsx-dev-runtime.js b/node_modules/@welldone-software/why-did-you-render/jsx-dev-runtime.js
2+
index fabd293..0d6a323 100644
3+
--- a/node_modules/@welldone-software/why-did-you-render/jsx-dev-runtime.js
4+
+++ b/node_modules/@welldone-software/why-did-you-render/jsx-dev-runtime.js
5+
@@ -5,8 +5,9 @@ var WDYR = require('@welldone-software/why-did-you-render')
6+
var origJsxDev = jsxDevRuntime.jsxDEV
7+
var wdyrStore = WDYR.wdyrStore
8+
9+
-module.exports = jsxDevRuntime
10+
-module.exports.jsxDEV = function jsxDEV(){
11+
+module.exports = {
12+
+ ...jsxDevRuntime,
13+
+ jsxDEV: function jsxDEV(){
14+
var args = Array.prototype.slice.call(arguments)
15+
16+
if(wdyrStore.React && wdyrStore.React.isWDYR){
17+
@@ -35,4 +36,4 @@ module.exports.jsxDEV = function jsxDEV(){
18+
}
19+
20+
return origJsxDev.apply(null, args)
21+
-}
22+
+}}

‎shared/react-native/packageAndBuild.sh‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,5 @@ sleep 5 && requestbundles &
4646
backgroundpid=$!
4747
trap 'kill $backgroundpid' EXIT # quit requestBundles on exit
4848
while true; do
49-
yarn react-native start
49+
yarn react-native start --reset-cache
5050
done

‎shared/util/container.tsx‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,7 @@ import type {ActionHandler as _ActionHandler} from './make-reducer'
55
import type {TypedState as _TypedState} from '../constants/reducer'
66
import {StatusCode} from '../constants/types/rpc-gen'
77
import {anyWaiting, anyErrors} from '../constants/waiting'
8-
import {
9-
useSelector as RRuseSelector,
10-
useDispatch as RRuseDispatch,
11-
type TypedUseSelectorHook,
12-
} from 'react-redux'
8+
import {useDispatch as RRuseDispatch, type TypedUseSelectorHook} from 'react-redux'
139
import type {Dispatch as RRDispatch} from 'redux'
1410
import flowRight from 'lodash/flowRight'
1511
import typedConnect from './typed-connect'
@@ -20,6 +16,9 @@ export type ListenerMiddleware = ReturnType<typeof createListenerMiddleware>
2016
export {type RouteProps, getRouteParams, getRouteParamsFromRoute} from '../router-v2/route-params'
2117
export {listenAction, type ListenerApi, spawn} from './redux-toolkit'
2218
export {useDebounce, useDebouncedCallback, useThrottledCallback, type DebouncedState} from 'use-debounce'
19+
import USH from './use-selector'
20+
21+
const useSelector = USH.useSelector as TypedUseSelectorHook<RootState>
2322

2423
// don't pay for this in prod builds
2524
if (!__DEV__) {
@@ -119,7 +118,7 @@ export {default as useRPC} from './use-rpc'
119118
export {default as useSafeCallback} from './use-safe-callback'
120119
export type RootState = _TypedState
121120
export const useDispatch = () => RRuseDispatch<RRDispatch<_TypedActions>>()
122-
export const useSelector: TypedUseSelectorHook<RootState> = RRuseSelector
121+
export {useSelector}
123122

124123
// BEGIN debugging connect
125124
// import isEqual from 'lodash/isEqual'

‎shared/util/use-selector.tsx‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// Only doing this indirection so we can easily patch using why did you render
2+
const {useSelector} = require('react-redux')
3+
const useSelectorHolder = {useSelector}
4+
export default useSelectorHolder

0 commit comments

Comments
 (0)