mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-05 06:28:51 +00:00
fix(phone): Fix subsequent rerenders & added WDYR (#209)
Fixed an issue with infinite rerendering on app routes by making it a Pure component. Adds `why-did-you-render` for development use. Co-authored-by: Taso <[email protected]>
This commit is contained in:
1 parent
4fceb3750b
commit
8dc59c47bd
7 files changed
+43
-27
No files matched your search
@@ -43,6 +43,7 @@
|
|||||||
"@types/react": "^16.9.51",
|
"@types/react": "^16.9.51",
|
||||||
"@types/react-dom": "^16.9.8",
|
"@types/react-dom": "^16.9.8",
|
||||||
"@types/react-router-dom": "^5.1.7",
|
"@types/react-router-dom": "^5.1.7",
|
||||||
|
"@welldone-software/why-did-you-render": "^6.1.1",
|
||||||
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.1",
|
"@wojtekmaj/enzyme-adapter-react-17": "^0.6.1",
|
||||||
"cp-cli": "^2.0.0",
|
"cp-cli": "^2.0.0",
|
||||||
"cross-env": "^7.0.2",
|
"cross-env": "^7.0.2",
|
||||||
|
|||||||
@@ -1,10 +1,14 @@
|
|||||||
import { useEffect } from 'react';
|
import { memo, useEffect } from 'react';
|
||||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||||
|
|
||||||
export const AppWithStartup = ({ children, id }) => {
|
const Component = ({ children, id }) => {
|
||||||
const Nui = useNuiRequest();
|
const Nui = useNuiRequest();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
Nui.send(`npwd:app:${id}`);
|
Nui.send(`npwd:app:${id}`);
|
||||||
}, [Nui, id]);
|
}, [Nui, id]);
|
||||||
return children;
|
return children;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const AppWithStartup = memo(Component, () => true);
|
||||||
|
|
||||||
|
export { AppWithStartup };
|
||||||
@@ -67,7 +67,7 @@ export const APPS: IAppConfig[] = [
|
|||||||
backgroundColor: MESSAGES_APP_PRIMARY_COLOR,
|
backgroundColor: MESSAGES_APP_PRIMARY_COLOR,
|
||||||
color: MESSAGES_APP_TEXT_COLOR,
|
color: MESSAGES_APP_TEXT_COLOR,
|
||||||
path: '/messages',
|
path: '/messages',
|
||||||
Route: () => <AppRoute id="MESSAGE" path="/messages" component={MessagesApp} />,
|
Route: () => <AppRoute id="MESSAGES" path="/messages" component={MessagesApp} />,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 'CONTACTS',
|
id: 'CONTACTS',
|
||||||
|
|||||||
@@ -2,11 +2,6 @@ import React from 'react';
|
|||||||
import { Box, makeStyles } from '@material-ui/core';
|
import { Box, makeStyles } from '@material-ui/core';
|
||||||
import { CallControls } from './CallControls';
|
import { CallControls } from './CallControls';
|
||||||
|
|
||||||
// interface ICallNotificationProps {
|
|
||||||
// onAccept(): void;
|
|
||||||
// onReject(): void;
|
|
||||||
// }
|
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
root: {
|
||||||
paddingBottom: '48px',
|
paddingBottom: '48px',
|
||||||
|
|||||||
@@ -49,15 +49,14 @@ const isKeyValid = (key) => validKeys.indexOf(key) !== -1;
|
|||||||
export const useKeyboardService = () => {
|
export const useKeyboardService = () => {
|
||||||
const history = useHistory();
|
const history = useHistory();
|
||||||
const { closePhone } = usePhone();
|
const { closePhone } = usePhone();
|
||||||
const getters = {
|
|
||||||
ArrowRight: useRecoilValue(keyboardState.ArrowRight),
|
const ArrowRight = useRecoilValue(keyboardState.ArrowRight);
|
||||||
ArrowLeft: useRecoilValue(keyboardState.ArrowLeft),
|
const ArrowLeft = useRecoilValue(keyboardState.ArrowLeft);
|
||||||
ArrowUp: useRecoilValue(keyboardState.ArrowUp),
|
const ArrowUp = useRecoilValue(keyboardState.ArrowUp);
|
||||||
ArrowDown: useRecoilValue(keyboardState.ArrowDown),
|
const ArrowDown = useRecoilValue(keyboardState.ArrowDown);
|
||||||
Backspace: useRecoilValue(keyboardState.Backspace),
|
const Backspace = useRecoilValue(keyboardState.Backspace);
|
||||||
Enter: useRecoilValue(keyboardState.Enter),
|
const Enter = useRecoilValue(keyboardState.Enter);
|
||||||
Escape: useRecoilValue(keyboardState.Escape),
|
const Escape = useRecoilValue(keyboardState.Escape);
|
||||||
};
|
|
||||||
|
|
||||||
const handlers = useRef(new Map());
|
const handlers = useRef(new Map());
|
||||||
const setEscape = useSetRecoilState<any>(keyboardState.Escape);
|
const setEscape = useSetRecoilState<any>(keyboardState.Escape);
|
||||||
@@ -65,15 +64,18 @@ export const useKeyboardService = () => {
|
|||||||
|
|
||||||
useEffect(
|
useEffect(
|
||||||
function registerCustomKeys() {
|
function registerCustomKeys() {
|
||||||
Object.keys(getters).forEach((g) => {
|
handlers.current.set('ArrowRight', ArrowRight);
|
||||||
handlers.current.set(g, getters[g]);
|
handlers.current.set('ArrowLeft', ArrowLeft);
|
||||||
});
|
handlers.current.set('ArrowUp', ArrowUp);
|
||||||
|
handlers.current.set('ArrowDown', ArrowDown);
|
||||||
|
handlers.current.set('Backspace', Backspace);
|
||||||
|
handlers.current.set('Enter', Enter);
|
||||||
|
handlers.current.set('Escape', Escape);
|
||||||
},
|
},
|
||||||
[getters],
|
[ArrowDown, ArrowLeft, ArrowRight, ArrowUp, Backspace, Enter, Escape],
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(
|
useEffect(function handleNUIKeyboardMessage() {
|
||||||
function handleNUIKeyboardMessage() {
|
|
||||||
function onKeyUp(event) {
|
function onKeyUp(event) {
|
||||||
const { key } = event;
|
const { key } = event;
|
||||||
const callback = handlers.current.get(key);
|
const callback = handlers.current.get(key);
|
||||||
@@ -84,9 +86,7 @@ export const useKeyboardService = () => {
|
|||||||
|
|
||||||
window.addEventListener('keyup', onKeyUp);
|
window.addEventListener('keyup', onKeyUp);
|
||||||
return () => window.removeEventListener('keyup', onKeyUp);
|
return () => window.removeEventListener('keyup', onKeyUp);
|
||||||
},
|
}, []);
|
||||||
[getters],
|
|
||||||
);
|
|
||||||
|
|
||||||
const backspaceHandler = useCallback(
|
const backspaceHandler = useCallback(
|
||||||
(event) => {
|
(event) => {
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
/// <reference types="@welldone-software/why-did-you-render" />
|
||||||
|
import React from 'react';
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
const whyDidYouRender = require('@welldone-software/why-did-you-render');
|
||||||
|
whyDidYouRender(React, {
|
||||||
|
trackAllPureComponents: true,
|
||||||
|
});
|
||||||
|
}
|
||||||
+8
-1
@@ -2381,6 +2381,13 @@
|
|||||||
"@webassemblyjs/wast-parser" "1.9.0"
|
"@webassemblyjs/wast-parser" "1.9.0"
|
||||||
"@xtuc/long" "4.2.2"
|
"@xtuc/long" "4.2.2"
|
||||||
|
|
||||||
|
"@welldone-software/why-did-you-render@^6.1.1":
|
||||||
|
version "6.1.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/@welldone-software/why-did-you-render/-/why-did-you-render-6.1.1.tgz#3dcf66620fcafbf79e5260bd6ace5e51254055ac"
|
||||||
|
integrity sha512-BMFp33T4MC27qvCWsI1SqwZCxIlxoQXsPQFdGLDsPSg7sgoWX4Gzj0+hlKVrWrCBiIxi7gP2JcS9IK6CZzk8mg==
|
||||||
|
dependencies:
|
||||||
|
lodash "^4"
|
||||||
|
|
||||||
"@wojtekmaj/enzyme-adapter-react-17@^0.6.1":
|
"@wojtekmaj/enzyme-adapter-react-17@^0.6.1":
|
||||||
version "0.6.1"
|
version "0.6.1"
|
||||||
resolved "https://registry.yarnpkg.com/@wojtekmaj/enzyme-adapter-react-17/-/enzyme-adapter-react-17-0.6.1.tgz#28caa37118c183e5f13c4dfb68cc32cde828ecbc"
|
resolved "https://registry.yarnpkg.com/@wojtekmaj/enzyme-adapter-react-17/-/enzyme-adapter-react-17-0.6.1.tgz#28caa37118c183e5f13c4dfb68cc32cde828ecbc"
|
||||||
@@ -7672,7 +7679,7 @@ lodash.uniq@^4.5.0:
|
|||||||
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
|
resolved "https://registry.yarnpkg.com/lodash.uniq/-/lodash.uniq-4.5.0.tgz#d0225373aeb652adc1bc82e4945339a842754773"
|
||||||
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=
|
integrity sha1-0CJTc662Uq3BvILklFM5qEJ1R3M=
|
||||||
|
|
||||||
"lodash@>=3.5 <5", lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17.5:
|
"lodash@>=3.5 <5", lodash@^4, lodash@^4.17.11, lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.20, lodash@^4.17.21, lodash@^4.17.5:
|
||||||
version "4.17.21"
|
version "4.17.21"
|
||||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
|
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
|
||||||
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
|
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
|
||||||
|
|||||||
Reference in new issue
Block a user