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

#9154: mod variable session sync (2/3) #9155

Open
wants to merge 5 commits into
base: feature/9137-variable-migration
Choose a base branch
from

Conversation

twschiller
Copy link
Contributor

@twschiller twschiller commented Sep 14, 2024

What does this PR do?

Remaining Work

Demo

  • See E2E test

Future Work

  • Delete a mod session's variables when the a mod is deactivated. That will require providing event contexts can listen to for when a mod is deactivated

For more information on our expectations for the PR process, see the
code review principles doc

@twschiller twschiller changed the base branch from main to feature/9137-variable-migration September 14, 2024 19:38
@twschiller twschiller added do not merge Merging of this PR is blocked by another one enhancement New feature or request labels Sep 14, 2024
@twschiller twschiller self-assigned this Sep 14, 2024
Copy link

codecov bot commented Sep 14, 2024

Codecov Report

Attention: Patch coverage is 46.47887% with 38 lines in your changes missing coverage. Please review.

Project coverage is 74.79%. Comparing base (465e19a) to head (36dc637).

Files with missing lines Patch % Lines
src/contentScript/stateController.ts 45.58% 37 Missing ⚠️
src/background/background.ts 0.00% 1 Missing ⚠️
Additional details and impacted files
@@                         Coverage Diff                         @@
##           feature/9137-variable-migration    #9155      +/-   ##
===================================================================
- Coverage                            74.83%   74.79%   -0.05%     
===================================================================
  Files                                 1355     1355              
  Lines                                41828    41882      +54     
  Branches                              7804     7816      +12     
===================================================================
+ Hits                                 31304    31324      +20     
- Misses                               10524    10558      +34     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@twschiller twschiller added this to the 2.1.2 milestone Sep 14, 2024
Copy link

Playwright test results

failed  2 failed
passed  125 passed
flaky  1 flaky
skipped  4 skipped

Details

report  Open report ↗︎
stats  132 tests across 44 suites
duration  11 minutes, 34 seconds
commit  36dc637
info  For more information on how to debug and view this report, see our readme

Failed tests

chrome › tests/pageEditor/addStarterBrick.spec.ts › Add starter brick to mod
msedge › tests/pageEditor/addStarterBrick.spec.ts › Add starter brick to mod

Flaky tests

msedge › tests/regressions/welcomeStarterBricks.spec.ts › #8740: can view the starter mods on the pixiebrix.com/welcome page

Skipped tests

chrome › tests/regressions/doNotCloseSidebarOnPageEditorSave.spec.ts › #8104: Do not automatically close the sidebar when saving in the Page Editor
msedge › tests/regressions/doNotCloseSidebarOnPageEditorSave.spec.ts › #8104: Do not automatically close the sidebar when saving in the Page Editor
chrome › tests/runtime/googleSheetsIntegration.spec.ts › can activate a google spreadsheet mod with config options
msedge › tests/runtime/googleSheetsIntegration.spec.ts › can activate a google spreadsheet mod with config options

@twschiller twschiller changed the title #9154: [WIP] mod variable session sync #9154: mod variable session sync Sep 14, 2024
@twschiller twschiller marked this pull request as ready for review September 14, 2024 21:49
Comment on lines +355 to +353
browser.storage.onChanged.addListener(onSessionStorageChange);
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to consider any cases when we should remove the listener?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, I see the note on future work in the PR description -

Delete a mod session's variables when the a mod is deactivated. That will require providing event contexts can listen to for when a mod is deactivated

I'd recommend to create a followup issue to do this work.

Copy link
Contributor Author

@twschiller twschiller Sep 17, 2024

Choose a reason for hiding this comment

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

I'd recommend to create a followup issue to do this work.

There will be one when the issue for the slice is created: https://www.notion.so/pixiebrix/Mod-variable-syncing-across-Page-Load-and-all-Frames-in-runtime-and-workshop-c533b56bc9ed4f6ea7aa8502439c632a?pvs=4#10143b21a25380f2a89ad449668fdaea

Also, we don't need to remove the listener. That comment is about actually deleting the data from session storage when the mod is deactivated

const key = getSessionStorageKey(modId);
// Skip call if there are no synchronized variables
const value = await browser.storage.session.get(key);
// eslint-disable-next-line security/detect-object-injection -- key passed to .get
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd like us to revisit removing this eslint rule at some point. I'm not sure there really is any practical place to consider this a security issue at the moment.

Copy link
Collaborator

Choose a reason for hiding this comment

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

💯

Comment on lines 180 to 185
document.dispatchEvent(
new CustomEvent(STATE_CHANGE_JS_EVENT_TYPE, {
detail,
bubbles: true,
}),
);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This might be a good time to refactor creating the event detail and dispatching to a helper method.

Copy link
Collaborator

Choose a reason for hiding this comment

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

See properEvent

Copy link
Contributor Author

@twschiller twschiller Sep 17, 2024

Choose a reason for hiding this comment

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

This might be a good time to refactor creating the event detail and dispatching to a helper method.

@grahamlangford @fungairino I'm not sure what you mean by the conversation - are you suggesting abstracting dispatch event and CustomEvent constructor? Or something else?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, I was suggesting abstracting creating the event payload and sending it in a helper method.

modState.clear();
framePrivateState.clear();
frameModState.clear();
modSyncPolicies.clear();
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This file is getting rather large... Maybe we can consider splitting up each of the types of state into their own separate modules

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Collaborator

@fungairino fungairino left a comment

Choose a reason for hiding this comment

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

Some suggestions for clean-up, organization and follow-ups but no blockers

Copy link

No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack.

Do not edit this comment manually.

@twschiller twschiller changed the title #9154: mod variable session sync #9154: mod variable session sync (2/3) Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge Merging of this PR is blocked by another one enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants