-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
[PM-3530] browser extension view cache #10437
Conversation
…ing; add route guard with warning dialog
Codecov ReportAttention: Patch coverage is
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## main #10437 +/- ##
==========================================
+ Coverage 32.79% 32.91% +0.11%
==========================================
Files 2670 2669 -1
Lines 81769 81824 +55
Branches 15414 15441 +27
==========================================
+ Hits 26816 26929 +113
+ Misses 52877 52805 -72
- Partials 2076 2090 +14 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wasn't around to review #9556 but from what I can see this looks good. It's gonna take some time to get used to signals, especially when used in a complex scenario like this
/** | ||
* - Initialize a form from a cached value | ||
* - Save form value to cache when it changes | ||
* - The form is marked dirty if the restored value is not `undefined`. | ||
**/ | ||
formGroup<TFormGroup extends FormGroup>(options: FormCacheOptions<TFormGroup>): TFormGroup { | ||
return options.control; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: This isn't actually true right? This is the behavior that's implemented by the popup version of this service, but not by this general service?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question @coroiu
Yes, the default implementation is noop. However, since we inject via the default implementation, I thought it would be more helpful to document the non-noop behavior so it will show up in IDE-hints.
Is this a bad idea, or is there a more clear way that you would suggest representing this?
Maybe just add Non browser extension implementations are noop.
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think adding your comment about non browser extensions is definitely a good idea.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added here 8ac50e4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I reacted because this was documenting an implementation which was obviously not providing that behavior. I'm not sure if we normally use classes as interfaces AND default implementations like this. I feel like I mostly see the interface defined and documented separately. That way this noop implementation could clearly document the fact that it is not living up to the interface documentation, and why that doesn't matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also provided the default implementation to other clients here: 1f22860
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the only thing I need is a comment on the formGroup
method mentioning its nuance.
Was discussing the feature flag strategy for this with @trmartin4 and we thought it might be nice to include the feature flag in the service logic instead of expecting consumers to flag it manually. Lmk what y'all think @justindbaur @coroiu. |
private updateState(key: string, value: string) { | ||
this.messageSender.send(SAVE_VIEW_CACHE_COMMAND, { | ||
key, | ||
value, | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: maybe we should disable this with the feature flag as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems reasonable to me. Added ff6e42a
🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-3530
📔 Objective
Split from #9556, see extra comments there.
Introduces a way to store temporary component state, for the purposes of persisting views between extension popup open and close.
ViewCacheService
.signal
, a wrapper around Angular Signals for caching arbitrary values.formGroup
, a wrapper around Angular Reactive Forms for caching dirty form valuesIn both instances, the wrapped object's value is set with the previously cached value. Updates to the wrapped value are saved to the cache.
State is stored in the
PopupViewCacheBackgroundService
, which clears cached state on unlock, lock, tab change, & 2min after closing the popup window. State is also cleared when navigating between routes in the extension popupOther approaches
I initially wanted to utilize a simpler, non-reactive API like the following, which accepts a cleanup function that runs when the popup's
pagehide
event occurs:However,
pagehide
(andvisibilitychange
/unload
) do not consistently fire in Chrome extension windows. :(Random thoughts
deserializer
field? See [PM-3530][PM-8588] persist extension route history #9556 (comment) but I could go either way.ViewCacheService.watch(formOrSignal, options)
📸 Screenshots
Screen.Recording.2024-07-02.at.9.58.27.AM.mov
⏰ Reminders before review
🦮 Reviewer guidelines
:+1:
) or similar for great changes:memo:
) or ℹ️ (:information_source:
) for notes or general info:question:
) for questions:thinking:
) or 💭 (:thought_balloon:
) for more open inquiry that's not quite a confirmed issue and could potentially benefit from discussion:art:
) for suggestions / improvements:x:
) or:warning:
) for more significant problems or concerns needing attention:seedling:
) or ♻️ (:recycle:
) for future improvements or indications of technical debt:pick:
) for minor or nitpick changes