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

✨ [devext] revamp extension settings #2250

Merged

Conversation

BenoitZugmeyer
Copy link
Member

@BenoitZugmeyer BenoitZugmeyer commented May 16, 2023

Motivation

The extension settings behaved a bit unexpectedly:

  • only a few settings were persisted
  • network rules were applied on every tab (even if the extension was closed or inactive on that tab)
  • settings that were persisted were sync across all devtools instances, making it hard to have different settings for different tabs.

Changes

This PR moves the settings logic from the background script to the devtools. No more "store", now all settings are loaded from the extension storage when the devtools is open. Every time a setting changes, it is written to the extension storage without overriding other settings. Devtools instances are not subscribing to settings updates,
so it is possible to edit the settings in a devtools instance independently from other instances, but still have persistence. This mimics how Chrome devtools settings are working.

Because the network rules are not driven by a global "store" anymore, they can be activated per tab, thanks to the devtools connection.

Testing

  • Local
  • Staging
  • Unit
  • End to end

I have gone over the contributing documentation.

Copy link
Member Author

@codecov-commenter
Copy link

Codecov Report

Merging #2250 (19606a0) into benoit/developer-extension--revamp-communication (c42d40f) will decrease coverage by 0.10%.
The diff coverage is n/a.

@@                                 Coverage Diff                                  @@
##           benoit/developer-extension--revamp-communication    #2250      +/-   ##
====================================================================================
- Coverage                                             94.09%   93.99%   -0.10%     
====================================================================================
  Files                                                   201      201              
  Lines                                                  6083     6083              
  Branches                                               1347     1347              
====================================================================================
- Hits                                                   5724     5718       -6     
- Misses                                                  359      365       +6     

see 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/developer-extension--settings-scoped-by-panel branch from 19606a0 to 8135d2f Compare May 16, 2023 17:09
Comment on lines +52 to +64
// https://legacy.reactjs.org/docs/hooks-faq.html#is-there-something-like-forceupdate
const [, forceUpdate] = useReducer((x: number) => x + 1, 0)

useEffect(() => {
const subscription = onSettingsChange.subscribe(forceUpdate)
Copy link
Contributor

Choose a reason for hiding this comment

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

💭 thought: ‏It is not clear to me why we need to do that, maybe adding a comment could help future reviewer as well

@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/developer-extension--revamp-communication branch from 3ec53f6 to fb22036 Compare May 17, 2023 12:35
@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/developer-extension--settings-scoped-by-panel branch from 45fb402 to a256c2a Compare May 17, 2023 12:37
Base automatically changed from benoit/developer-extension--revamp-communication to main May 17, 2023 13:04
This commit changes the way we define network rules to make sure they
only apply on the tab where the devtools panel is open.

When the devtools tab is closed, rules are cleared.
This commit removes the background store usage for settings.
Get rid of the store defined in the background script as it is not used
anymore.
@BenoitZugmeyer BenoitZugmeyer force-pushed the benoit/developer-extension--settings-scoped-by-panel branch from a256c2a to 2573add Compare May 17, 2023 13:24
@BenoitZugmeyer BenoitZugmeyer merged commit 1d77068 into main May 17, 2023
@BenoitZugmeyer BenoitZugmeyer deleted the benoit/developer-extension--settings-scoped-by-panel branch May 17, 2023 14:52
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.

3 participants