From a9e36d4a9c3cffc13df72dcd0cf5c1aadcffd730 Mon Sep 17 00:00:00 2001 From: Zhiyuan Zheng Date: Wed, 1 Jun 2022 00:33:59 +0200 Subject: [PATCH] Try without memo --- babel.config.js | 14 +- package.json | 1 + src/api/tooot.ts | 2 +- src/components/Timeline/Default.tsx | 239 +++++++++++++--------------- src/startup/dev.ts | 2 + src/utils/queryHooks/timeline.ts | 4 +- yarn.lock | 55 ++++++- 7 files changed, 188 insertions(+), 129 deletions(-) diff --git a/babel.config.js b/babel.config.js index 576c1c12..630526a3 100644 --- a/babel.config.js +++ b/babel.config.js @@ -29,7 +29,19 @@ module.exports = function (api) { } return { - presets: ['babel-preset-expo'], + presets: [ + 'babel-preset-expo', + [ + '@babel/preset-react', + { + importSource: '@welldone-software/why-did-you-render', + runtime: 'automatic', + development: + process.env.NODE_ENV === 'development' || + process.env.BABEL_ENV === 'development' + } + ] + ], plugins } } diff --git a/package.json b/package.json index f966803b..31e142ae 100644 --- a/package.json +++ b/package.json @@ -104,6 +104,7 @@ "devDependencies": { "@babel/core": "7.18.2", "@babel/plugin-proposal-optional-chaining": "7.17.12", + "@babel/preset-react": "^7.17.12", "@babel/preset-typescript": "7.17.12", "@expo/config": "6.0.24", "@types/lodash": "4.14.182", diff --git a/src/api/tooot.ts b/src/api/tooot.ts index db5c86af..b4264a76 100644 --- a/src/api/tooot.ts +++ b/src/api/tooot.ts @@ -19,7 +19,7 @@ export type Params = { export const TOOOT_API_DOMAIN = mapEnvironment({ release: 'api.tooot.app', - candidate: 'api.tooot.app', + candidate: 'api-candidate.tooot.app', development: 'api-development.tooot.app' }) diff --git a/src/components/Timeline/Default.tsx b/src/components/Timeline/Default.tsx index cba31325..9d863144 100644 --- a/src/components/Timeline/Default.tsx +++ b/src/components/Timeline/Default.tsx @@ -14,7 +14,7 @@ import { QueryKeyTimeline } from '@utils/queryHooks/timeline' import { getInstanceAccount } from '@utils/slices/instancesSlice' import { StyleConstants } from '@utils/styles/constants' import { useTheme } from '@utils/styles/ThemeManager' -import { isEqual, uniqBy } from 'lodash' +import { uniqBy } from 'lodash' import React, { useCallback } from 'react' import { Pressable, View } from 'react-native' import { useSelector } from 'react-redux' @@ -34,145 +34,136 @@ export interface Props { } // When the poll is long -const TimelineDefault = React.memo( - ({ - item, - queryKey, - rootQueryKey, - origin, - highlighted = false, - disableDetails = false, - disableOnPress = false - }: Props) => { - const { colors } = useTheme() - const instanceAccount = useSelector(getInstanceAccount, () => true) - const navigation = - useNavigation>() +const TimelineDefault: React.FC = ({ + item, + queryKey, + rootQueryKey, + origin, + highlighted = false, + disableDetails = false, + disableOnPress = false +}) => { + const { colors } = useTheme() + const instanceAccount = useSelector(getInstanceAccount, () => true) + const navigation = + useNavigation>() - const actualStatus = item.reblog ? item.reblog : item + const actualStatus = item.reblog ? item.reblog : item - const ownAccount = actualStatus.account?.id === instanceAccount?.id + const ownAccount = actualStatus.account?.id === instanceAccount?.id - if ( + if ( + !highlighted && + queryKey && + shouldFilter({ status: actualStatus, queryKey }) + ) { + return + } + + const onPress = useCallback(() => { + analytics('timeline_default_press', { + page: queryKey ? queryKey[1].page : origin + }) + !disableOnPress && !highlighted && - queryKey && - shouldFilter({ status: actualStatus, queryKey }) - ) { - return - } - - const onPress = useCallback(() => { - analytics('timeline_default_press', { - page: queryKey ? queryKey[1].page : origin + navigation.push('Tab-Shared-Toot', { + toot: actualStatus, + rootQueryKey: queryKey }) - !disableOnPress && - !highlighted && - navigation.push('Tab-Shared-Toot', { - toot: actualStatus, - rootQueryKey: queryKey - }) - }, []) + }, []) - return ( - + {item.reblog ? ( + + ) : item._pinned ? ( + + ) : null} + + + + + + + - {item.reblog ? ( - - ) : item._pinned ? ( - - ) : null} - - - - 0 ? ( + - - - - {typeof actualStatus.content === 'string' && - actualStatus.content.length > 0 ? ( - - ) : null} - {queryKey && actualStatus.poll ? ( - - ) : null} - {!disableDetails && - Array.isArray(actualStatus.media_attachments) && - actualStatus.media_attachments.length ? ( - - ) : null} - {!disableDetails && actualStatus.card ? ( - - ) : null} - {!disableDetails ? ( - - ) : null} - - - - - {queryKey && !disableDetails ? ( - d?.id !== instanceAccount?.id), - d => d?.id - ).map(d => d?.acct)} + statusId={actualStatus.id} + poll={actualStatus.poll} reblog={item.reblog ? true : false} + sameAccount={ownAccount} /> ) : null} - - ) - }, - (prev, next) => isEqual(prev.item, next.item) -) + {!disableDetails && + Array.isArray(actualStatus.media_attachments) && + actualStatus.media_attachments.length ? ( + + ) : null} + {!disableDetails && actualStatus.card ? ( + + ) : null} + {!disableDetails ? ( + + ) : null} + + + + + {queryKey && !disableDetails ? ( + d?.id !== instanceAccount?.id), + d => d?.id + ).map(d => d?.acct)} + reblog={item.reblog ? true : false} + /> + ) : null} + + ) +} export default TimelineDefault diff --git a/src/startup/dev.ts b/src/startup/dev.ts index c9d81e97..0c2d2df5 100644 --- a/src/startup/dev.ts +++ b/src/startup/dev.ts @@ -1,3 +1,5 @@ +/// + import React from 'react' import log from './log' diff --git a/src/utils/queryHooks/timeline.ts b/src/utils/queryHooks/timeline.ts index 1c4b28bb..cc30c82c 100644 --- a/src/utils/queryHooks/timeline.ts +++ b/src/utils/queryHooks/timeline.ts @@ -440,8 +440,8 @@ const useTimelineMutation = ({ ...(onMutate && { onMutate: params => { queryClient.cancelQueries(params.queryKey) - let oldData - params.queryKey && (oldData = queryClient.getQueryData(params.queryKey)) + const oldData = + params.queryKey && queryClient.getQueryData(params.queryKey) haptics('Light') switch (params.type) { diff --git a/yarn.lock b/yarn.lock index a229dda8..49a7062e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -693,6 +693,13 @@ dependencies: "@babel/helper-plugin-utils" "^7.16.7" +"@babel/plugin-syntax-jsx@^7.17.12": + version "7.17.12" + resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.17.12.tgz#834035b45061983a491f60096f61a2e7c5674a47" + integrity sha512-spyY3E3AURfxh/RHtjx5j6hs8am5NbUBGfcZ2vB3uShSpZdQyXSf5rR5Mk76vbtlAZOelyVQ71Fg0x9SG4fsog== + dependencies: + "@babel/helper-plugin-utils" "^7.17.12" + "@babel/plugin-syntax-logical-assignment-operators@^7.10.4": version "7.10.4" resolved "https://registry.yarnpkg.com/@babel/plugin-syntax-logical-assignment-operators/-/plugin-syntax-logical-assignment-operators-7.10.4.tgz#ca91ef46303530448b906652bac2e9fe9941f699" @@ -973,13 +980,20 @@ dependencies: "@babel/helper-plugin-utils" "^7.16.7" -"@babel/plugin-transform-react-display-name@^7.0.0": +"@babel/plugin-transform-react-display-name@^7.0.0", "@babel/plugin-transform-react-display-name@^7.16.7": version "7.16.7" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-display-name/-/plugin-transform-react-display-name-7.16.7.tgz#7b6d40d232f4c0f550ea348593db3b21e2404340" integrity sha512-qgIg8BcZgd0G/Cz916D5+9kqX0c7nPZyXaP8R2tLNN5tkyIZdG5fEwBrxwplzSnjC1jvQmyMNVwUCZPcbGY7Pg== dependencies: "@babel/helper-plugin-utils" "^7.16.7" +"@babel/plugin-transform-react-jsx-development@^7.16.7": + version "7.16.7" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx-development/-/plugin-transform-react-jsx-development-7.16.7.tgz#43a00724a3ed2557ed3f276a01a929e6686ac7b8" + integrity sha512-RMvQWvpla+xy6MlBpPlrKZCMRs2AGiHOGHY3xRwl0pEeim348dDyxeH4xBsMPbIMhujeq7ihE702eM2Ew0Wo+A== + dependencies: + "@babel/plugin-transform-react-jsx" "^7.16.7" + "@babel/plugin-transform-react-jsx-self@^7.0.0": version "7.16.7" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx-self/-/plugin-transform-react-jsx-self-7.16.7.tgz#f432ad0cba14c4a1faf44f0076c69e42a4d4479e" @@ -1005,6 +1019,25 @@ "@babel/plugin-syntax-jsx" "^7.16.7" "@babel/types" "^7.17.0" +"@babel/plugin-transform-react-jsx@^7.16.7", "@babel/plugin-transform-react-jsx@^7.17.12": + version "7.17.12" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-jsx/-/plugin-transform-react-jsx-7.17.12.tgz#2aa20022709cd6a3f40b45d60603d5f269586dba" + integrity sha512-Lcaw8bxd1DKht3thfD4A12dqo1X16he1Lm8rIv8sTwjAYNInRS1qHa9aJoqvzpscItXvftKDCfaEQzwoVyXpEQ== + dependencies: + "@babel/helper-annotate-as-pure" "^7.16.7" + "@babel/helper-module-imports" "^7.16.7" + "@babel/helper-plugin-utils" "^7.17.12" + "@babel/plugin-syntax-jsx" "^7.17.12" + "@babel/types" "^7.17.12" + +"@babel/plugin-transform-react-pure-annotations@^7.16.7": + version "7.18.0" + resolved "https://registry.yarnpkg.com/@babel/plugin-transform-react-pure-annotations/-/plugin-transform-react-pure-annotations-7.18.0.tgz#ef82c8e310913f3522462c9ac967d395092f1954" + integrity sha512-6+0IK6ouvqDn9bmEG7mEyF/pwlJXVj5lwydybpyyH3D0A7Hftk+NCTdYjnLNZksn261xaOV5ksmp20pQEmc2RQ== + dependencies: + "@babel/helper-annotate-as-pure" "^7.16.7" + "@babel/helper-plugin-utils" "^7.17.12" + "@babel/plugin-transform-regenerator@^7.0.0", "@babel/plugin-transform-regenerator@^7.16.7": version "7.16.7" resolved "https://registry.yarnpkg.com/@babel/plugin-transform-regenerator/-/plugin-transform-regenerator-7.16.7.tgz#9e7576dc476cb89ccc5096fff7af659243b4adeb" @@ -1200,6 +1233,18 @@ "@babel/types" "^7.4.4" esutils "^2.0.2" +"@babel/preset-react@^7.17.12": + version "7.17.12" + resolved "https://registry.yarnpkg.com/@babel/preset-react/-/preset-react-7.17.12.tgz#62adbd2d1870c0de3893095757ed5b00b492ab3d" + integrity sha512-h5U+rwreXtZaRBEQhW1hOJLMq8XNJBQ/9oymXiCXTuT/0uOwpbT0gUt+sXeOqoXBgNuUKI7TaObVwoEyWkpFgA== + dependencies: + "@babel/helper-plugin-utils" "^7.17.12" + "@babel/helper-validator-option" "^7.16.7" + "@babel/plugin-transform-react-display-name" "^7.16.7" + "@babel/plugin-transform-react-jsx" "^7.17.12" + "@babel/plugin-transform-react-jsx-development" "^7.16.7" + "@babel/plugin-transform-react-pure-annotations" "^7.16.7" + "@babel/preset-typescript@7.17.12": version "7.17.12" resolved "https://registry.yarnpkg.com/@babel/preset-typescript/-/preset-typescript-7.17.12.tgz#40269e0a0084d56fc5731b6c40febe1c9a4a3e8c" @@ -1332,6 +1377,14 @@ "@babel/helper-validator-identifier" "^7.16.7" to-fast-properties "^2.0.0" +"@babel/types@^7.17.12": + version "7.18.4" + resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.18.4.tgz#27eae9b9fd18e9dccc3f9d6ad051336f307be354" + integrity sha512-ThN1mBcMq5pG/Vm2IcBmPPfyPXbd8S02rS+OBIDENdufvqC7Z/jHPCv9IcP01277aKtDI8g/2XysBN4hA8niiw== + dependencies: + "@babel/helper-validator-identifier" "^7.16.7" + to-fast-properties "^2.0.0" + "@babel/types@^7.18.0", "@babel/types@^7.18.2": version "7.18.2" resolved "https://registry.yarnpkg.com/@babel/types/-/types-7.18.2.tgz#191abfed79ebe6f4242f643a9a5cbaa36b10b091"