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

fix: breaking selector due to missing controller state #12375

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

Prithpal-Sooriya
Copy link
Contributor

@Prithpal-Sooriya Prithpal-Sooriya commented Nov 21, 2024

Description

The selector is trying to access some engine state that is removed at build time through code-fences.
This fix ensures that the selectors are using the engine state or default to the controllers default state.

Long term - we need to investigate and ensure that the UI is not calling the selectors.

Related issues

Fixes: #11909

Manual testing steps

  1. Can you start up the application without it breaking?

Screenshots/Recordings

Before / After Recording
https://www.loom.com/share/badc4b4cd3b0446486497973dcf337f6?sid=33bcfe23-c495-41bf-89f5-e57b4b72e3d2

I was not able to replicate the controller state being undefined/missing, so forced it to be undefined when testing.

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

the selector is trying to access some engine state that is removed at build time through code-fences.

Long term - we need to investigate and ensure that the UI is not calling the selectors.
@Prithpal-Sooriya Prithpal-Sooriya requested a review from a team as a code owner November 21, 2024 16:15
Copy link
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-notifications Notifications team label Nov 21, 2024
@Prithpal-Sooriya Prithpal-Sooriya added the Run Smoke E2E Triggers smoke e2e on Bitrise label Nov 21, 2024
Copy link
Contributor

github-actions bot commented Nov 21, 2024

https://bitrise.io/ Bitrise

❌❌❌ pr_smoke_e2e_pipeline failed on Bitrise! ❌❌❌

Commit hash: 4540de3
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/fa2865f3-b5ee-4385-9ece-7bc947326d7d

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

Tip

  • Check the documentation if you have any doubts on how to understand the failure on bitrise

matteoscurati
matteoscurati previously approved these changes Nov 21, 2024
Copy link
Contributor

@matteoscurati matteoscurati left a comment

Choose a reason for hiding this comment

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

LGTM

@sethkfman
Copy link
Contributor

@Prithpal-Sooriya can you show manual confirmation this has fixed the issue?

mathieuartu
mathieuartu previously approved these changes Nov 21, 2024
Comment on lines +24 to +25
state?.engine?.backgroundState?.UserStorageController ??
UserStorageController.defaultState;
Copy link
Contributor Author

@Prithpal-Sooriya Prithpal-Sooriya Nov 22, 2024

Choose a reason for hiding this comment

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

This is the main fix for the missing controller state.

It is really odd that the controller state is missing sometimes. I have a hypothesis, but it is hard to prove.

Maybe we should have it as mobile best practice to "distrust controller state", or maybe at the type level make the controllers partial/optional (but this would be a large breaking change).

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 think I prefer this selector default state approach instead of migrations, as the redux state should do a second re-hydration once the engine has been initialised. We can then keep migrations only for state patches/fixes.

Copy link
Contributor

Choose a reason for hiding this comment

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

The easiest way to proof this is creating a migration for testing purposes and delete the UserStorageController data if exists, wdyt?

Comment on lines +35 to +37
if (!isNotificationsFeatureEnabled()) {
return;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All these other changes to hooks is to ensure we aren't unintentionally calling these hooks when the feature is off.

@Prithpal-Sooriya Prithpal-Sooriya requested a review from a team as a code owner November 22, 2024 11:13
@Prithpal-Sooriya Prithpal-Sooriya changed the title fix: breaking selector fix: breaking selector due to missing controller state Nov 22, 2024
@@ -3583,188 +3583,8 @@ exports[`SecuritySettings should render correctly 1`] = `
swipeDirection="down"
swipeThreshold={100}
transparent={true}
visible={true}
>
<View
Copy link
Contributor Author

@Prithpal-Sooriya Prithpal-Sooriya Nov 22, 2024

Choose a reason for hiding this comment

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

Snapshot change as we are now not calling any notification hooks during a side effect.

TODO: I want us to clean up/remove this effect:

useEffect(() => {
const triggerCascadeBasicFunctionalityDisable = async () => {
if (!isBasicFunctionalityEnabled) {
isNotificationEnabled && (await disableNotifications());
isProfileSyncingEnabled && (await disableProfileSyncing());
}
};
triggerCascadeBasicFunctionalityDisable();

I don't want side effects to cascade the updates for basic functionality (especially since this can be re-invoked from dependency changes). Instead I want this to be done during the basic functionality switch-off.

@Prithpal-Sooriya Prithpal-Sooriya added Run Smoke E2E Triggers smoke e2e on Bitrise and removed Run Smoke E2E Triggers smoke e2e on Bitrise labels Nov 22, 2024
Copy link
Contributor

github-actions bot commented Nov 22, 2024

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: 344002f
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/27765754-fa23-4f5a-9405-4be22391be53

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@Prithpal-Sooriya
Copy link
Contributor Author

@sethkfman I've attached a recording for a before and after the changes.

I've also sneaked in some other changes to ensure notification hooks are not called when the feature is disabled.
If this is too many changes, I'm happy to make them separate PRs.

Copy link

sonarcloud bot commented Nov 22, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Run Smoke E2E Triggers smoke e2e on Bitrise team-notifications Notifications team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Sentry] TypeError: undefined is not an object (evaluating 't.isProfileSyncingEnabled')
6 participants