Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: replace proxy-memoize with reselect #15333

Merged
merged 1 commit into from
Nov 11, 2024

Conversation

Nodonisko
Copy link
Contributor

@Nodonisko Nodonisko commented Nov 10, 2024

Description

I migrated from proxy-memoize because it was too magical and caused issues that some selectors did not updated correctly randomly and we were also stucked on old version because on new it was even worse and it throwed some errors on mobile too.

Reselect is more standart library and it works, even that DX is somewhat worse especially when you have multiple nested parametrized selectors.

Related Issue

Resolve #14785

Screenshots:

@Nodonisko Nodonisko requested review from a team, tomasklim and matejkriz as code owners November 10, 2024 17:15
Copy link

github-actions bot commented Nov 10, 2024

🚀 Expo preview is ready!

  • Project → trezor-suite-preview
  • Platforms → android, ios
  • Scheme → trezorsuitelite
  • Runtime Version → 10
  • More info

Learn more about 𝝠 Expo Github Action

@Nodonisko Nodonisko force-pushed the chore/replace-proxy-memoize branch from 169420a to 9670ecd Compare November 10, 2024 21:05
Copy link
Contributor

@PeKne PeKne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested and works good. I did not encounter any performance drop or crash 👏

@@ -147,303 +150,300 @@ export const prepareAccountsReducer = createReducerWithExtraDeps(
},
);

export const selectAccounts = (state: AccountsRootState) => state.wallet.accounts;
const createAppSelector = createWeakMapSelector.withTypes<
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this has ...App... in the name?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about changing it to createMemoizedSelector?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's taken from their docs, but createMemoizedSelector looks good

@@ -66,7 +65,7 @@ export type TransactionsRootState = {
transactions: { [key: AccountKey]: (WalletAccountTransaction | null | undefined)[] };
};
};
};
} & AccountsRootState;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that it will be sufficient to send a only one RootState type to the useSelector() call? Love it 👏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea, I don't see reason why not to do this

@@ -1,4 +1,4 @@
/* eslint-disable no-console */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be probably returned

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't throw anywhere so I guess it's fine

export const selectAccountTokenTransactions = createAppSelector(
[
selectAccountTransactions,
(_state, _accountKey: AccountKey, tokenAddress: TokenAddress) => tokenAddress,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn, this is so ugly that you have to pass a function instead of a simple argument value 🥴. But it is how it is

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's even worse if you have multiple nested selectors with different params :D

Comment on lines +65 to +66
(_state, domain: ContextDomain) => domain,
(_state, _domain, language: string) => language,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:

Suggested change
(_state, domain: ContextDomain) => domain,
(_state, _domain, language: string) => language,
(_state, domain: ContextDomain, language: string) => {domain, language},

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure, but I think this will break memoization, but IDK

@Nodonisko Nodonisko force-pushed the chore/replace-proxy-memoize branch 4 times, most recently from 7453135 to 3c00e24 Compare November 11, 2024 15:39
@matejkriz
Copy link
Member

Could you please provide some at least basic PR description why this change is happening?

@Nodonisko Nodonisko force-pushed the chore/replace-proxy-memoize branch from 3c00e24 to 14579f9 Compare November 11, 2024 16:01
@Nodonisko
Copy link
Contributor Author

@matejkriz done

@bosomt
Copy link
Contributor

bosomt commented Nov 11, 2024

QA OK

tested on all and academic seed

  • discovery
  • adding account
  • send tx

Info:

  • Suite version: web 24.12.0 (c4aeab2)
  • Browser: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
  • OS: MacIntel
  • Screen: 1512x982
  • Device: Trezor T3T1 2.8.3 regular (revision 7f373ae71eca855dd41b4a0fdcc7cadaa13a8281)
  • Transport: BridgeTransport 3.0.0-bundled.24.12.0

Copy link
Member

@matejkriz matejkriz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my testing it looks ok and I'm really glad we finally get rid off the magic proxy-memoize that I spent lot of hours debugging 🎉

@Nodonisko Nodonisko force-pushed the chore/replace-proxy-memoize branch from 14579f9 to 8d94d01 Compare November 11, 2024 21:08
@Nodonisko Nodonisko merged commit a33bf1d into develop Nov 11, 2024
69 checks passed
@Nodonisko Nodonisko deleted the chore/replace-proxy-memoize branch November 11, 2024 22:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Skeleton remains in the last coins fiat value on the dashboard after discovery
4 participants