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

refactor: clean up profile sync hooks #28132

Merged
merged 4 commits into from
Oct 29, 2024

Conversation

Prithpal-Sooriya
Copy link
Contributor

@Prithpal-Sooriya Prithpal-Sooriya commented Oct 28, 2024

Description

These changes make it easier for us to extend and add other syncing features.

Originally this was part of my local network sync feature, but decoupled parts of it since the change are a lot.

Open in GitHub Codespaces

Related issues

Fixes: N/A

Manual testing steps

There should be no changes as this is a code refactor and the interfaces/exports do not change.

Screenshots/Recordings

Before

After

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.

@Prithpal-Sooriya Prithpal-Sooriya requested review from a team as code owners October 28, 2024 18:00
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.

@github-actions github-actions bot added the team-notifications DEPRECATED: Use "team-assets" instead label Oct 28, 2024
@@ -1,6 +1,9 @@
import type { InternalAccount } from '@metamask/keyring-api';
import { SubjectMetadata } from '@metamask/permission-controller';
import { KeyringType } from '../hooks/metamask-notifications/useProfileSyncing';
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 did not like this selector type importing the profile-sync type.

Instead copied the type here, and the accounts team can provide a better narrow type.

@metamaskbot
Copy link
Collaborator

Builds ready [b4eafe7]
Page Load Metrics (2341 ± 87 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint39728952069697335
domContentLoaded19612786231018087
load19742794234118287
domInteractive33100582110
backgroundConnect973312411
firstReactRender581541152210
getState766382110
initialActions01000
loadScripts14622148174915273
setupStore1288282010
uiStartup22473159260719795
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 2.01 KiB (0.03%)
  • common: 0 Bytes (0.00%)

Comment on lines +105 to +114
* @template {(...args: any) => any} Hook
* @template {Parameters<Hook>} HookParams
* @template {ReturnType<Hook>} HookReturn
* @template {import('@testing-library/react-hooks').RenderHookResult<HookParams, HookReturn>} RenderHookResult
* @template {import('history').History} History
* @param {Hook} hook - The hook to be rendered.
* @param [state] - The initial state for the store.
* @param [pathname] - The initial pathname for the history.
* @param [Container] - An optional container component.
* @returns {RenderHookResult & { history: History }} The result of the rendered hook and the history object.
Copy link
Contributor Author

@Prithpal-Sooriya Prithpal-Sooriya Oct 28, 2024

Choose a reason for hiding this comment

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

JSDOC is actually pretty powerful. I did not know we can utilise generics.
This give us a nicer return type which gives us correct intellisense when creating tests.

const hook = renderWithProviderTyped(() => useMyFoo())
hook.result.callBar() // <-- this will now autocomplete and give us info on return/params required

We can migrate this over to TS in a diff PR (along with the other render helper functions in this file).

Copy link
Contributor Author

@Prithpal-Sooriya Prithpal-Sooriya Oct 28, 2024

Choose a reason for hiding this comment

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

As for why not adding JSDOC to the original function - I tested this, but many other tests that use this function failed TSC (due to not using the correct result.current type or passing incorrect arguments)

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 we can get a follow-up PR to add the JSDOC types to the original function, and fix the type issues on other files.

It might require coordinating with other teams to make sure that the type fixes are expected.

@metamaskbot
Copy link
Collaborator

Builds ready [246ede3]
Page Load Metrics (2200 ± 214 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint38138582026692332
domContentLoaded181137882162442212
load185738512200445214
domInteractive18153513014
backgroundConnect1079322110
firstReactRender521991073316
getState56320209
initialActions01000
loadScripts133532081627418201
setupStore1295332713
uiStartup210241182435453218
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 2.01 KiB (0.03%)
  • common: 0 Bytes (0.00%)

these changes make it easier for us to extend and add other syncing features
create a JSDOC typed version which is easier to use
@Prithpal-Sooriya Prithpal-Sooriya force-pushed the refactor/cleanup-profile-syncing-hooks branch from 246ede3 to d2ae206 Compare October 28, 2024 20:18
@metamaskbot
Copy link
Collaborator

Builds ready [d2ae206]
Page Load Metrics (2016 ± 65 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint40323911926370178
domContentLoaded17682301198012560
load17782392201613665
domInteractive20218604120
backgroundConnect790322813
firstReactRender53140972110
getState566182010
initialActions01000
loadScripts12741712146311053
setupStore1175382612
uiStartup19982658223514771
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 2.01 KiB (0.03%)
  • common: 0 Bytes (0.00%)

Copy link
Contributor

@mathieuartu mathieuartu left a comment

Choose a reason for hiding this comment

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

LGTM!

@metamaskbot
Copy link
Collaborator

Builds ready [f7fb949]
Page Load Metrics (1914 ± 98 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint17012625191520598
domContentLoaded169026061884208100
load16992627191420398
domInteractive17241665526
backgroundConnect979302010
firstReactRender482961075526
getState55917199
initialActions01000
loadScripts12562100141519895
setupStore1267282110
uiStartup189928372143243117
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 2.01 KiB (0.03%)
  • common: 0 Bytes (0.00%)

@Prithpal-Sooriya Prithpal-Sooriya added this pull request to the merge queue Oct 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 29, 2024
@metamaskbot
Copy link
Collaborator

Builds ready [df0cf4a]
Page Load Metrics (1994 ± 53 ms)
PlatformPageMetricMin (ms)Max (ms)Average (ms)StandardDeviation (ms)MarginOfError (ms)
ChromeHomefirstPaint18332200199510952
domContentLoaded1823216619689947
load18322208199411053
domInteractive188245199
backgroundConnect997242211
firstReactRender572201194120
getState566282512
initialActions01000
loadScripts1312161414438541
setupStore1394332613
uiStartup20512744227519192
Bundle size diffs
  • background: 0 Bytes (0.00%)
  • ui: 2.01 KiB (0.03%)
  • common: 0 Bytes (0.00%)

@Prithpal-Sooriya Prithpal-Sooriya added this pull request to the merge queue Oct 29, 2024
Merged via the queue into develop with commit 6eae9bc Oct 29, 2024
76 checks passed
@Prithpal-Sooriya Prithpal-Sooriya deleted the refactor/cleanup-profile-syncing-hooks branch October 29, 2024 13:36
@github-actions github-actions bot locked and limited conversation to collaborators Oct 29, 2024
@metamaskbot metamaskbot added the release-12.7.0 Issue or pull request that will be included in release 12.7.0 label Oct 29, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-12.7.0 Issue or pull request that will be included in release 12.7.0 team-notifications DEPRECATED: Use "team-assets" instead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants