Skip to content

Allow notifications to be registered and immediately shown #10782

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

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

tofumatt
Copy link
Collaborator

@tofumatt tofumatt commented May 16, 2025

Summary

Addresses issue:

PR Author Checklist

  • My code is tested and passes existing unit tests.
  • My code has an appropriate set of unit tests which all pass.
  • My code is backward-compatible with WordPress 5.2 and PHP 7.4.
  • My code follows the WordPress coding standards.
  • My code has proper inline documentation.
  • I have added a QA Brief on the issue linked above.
  • I have signed the Contributor License Agreement (see https://cla.developers.google.com/).

Do not alter or remove anything below. The following sections will be managed by moderators only.

Code Reviewer Checklist

  • Run the code.
  • Ensure the acceptance criteria are satisfied.
  • Reassess the implementation with the IB.
  • Ensure no unrelated changes are included.
  • Ensure CI checks pass.
  • Check Storybook where applicable.
  • Ensure there is a QA Brief.
  • Ensure there are no unexpected significant changes to file sizes.

Merge Reviewer Checklist

  • Ensure the PR has the correct target branch.
  • Double-check that the PR is okay to be merged.
  • Ensure the corresponding issue has a ZenHub release assigned.
  • Add a changelog message to the issue.

Copy link

github-actions bot commented May 16, 2025

Size Change: +822 B (+0.04%)

Total Size: 2.08 MB

ℹ️ View Unchanged
Filename Size Change
./dist/assets/css/googlesitekit-admin-css-********************.min.css 64.9 kB 0 B
./dist/assets/css/googlesitekit-adminbar-css-********************.min.css 11.8 kB 0 B
./dist/assets/css/googlesitekit-authorize-application-css-********************.min.css 846 B 0 B
./dist/assets/css/googlesitekit-wp-dashboard-css-********************.min.css 8.46 kB 0 B
./dist/assets/js/32-********************.js 2.76 kB 0 B
./dist/assets/js/33-********************.js 2.25 kB 0 B
./dist/assets/js/34-********************.js 3.64 kB 0 B
./dist/assets/js/35-********************.js 936 B 0 B
./dist/assets/js/36-********************.js 893 B 0 B
./dist/assets/js/37-********************.js 1.61 kB 0 B
./dist/assets/js/38-********************.js 1.57 kB 0 B
./dist/assets/js/39-********************.js 1.61 kB 0 B
./dist/assets/js/40-********************.js 1.59 kB 0 B
./dist/assets/js/41-********************.js 1.82 kB 0 B
./dist/assets/js/42-********************.js 3.12 kB 0 B
./dist/assets/js/analytics-advanced-tracking-********************.js 903 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/block-editor-plugin/editor-styles.css 124 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/block-editor-plugin/editor-styles.js 491 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/block-editor-plugin/index.js 8.38 kB 0 B
./dist/assets/js/blocks/reader-revenue-manager/common/editor-styles.css 307 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/common/editor-styles.js 492 B 0 B
./dist/assets/js/blocks/reader-revenue-manager/contribute-with-google/index.js 9.4 kB 0 B
./dist/assets/js/blocks/reader-revenue-manager/contribute-with-google/non-site-kit-user.js 8.9 kB 0 B
./dist/assets/js/blocks/reader-revenue-manager/subscribe-with-google/index.js 9.41 kB 0 B
./dist/assets/js/blocks/reader-revenue-manager/subscribe-with-google/non-site-kit-user.js 8.91 kB 0 B
./dist/assets/js/blocks/sign-in-with-google/editor-styles.css 84 B 0 B
./dist/assets/js/blocks/sign-in-with-google/editor-styles.js 492 B 0 B
./dist/assets/js/blocks/sign-in-with-google/index.js 18.1 kB 0 B
./dist/assets/js/googlesitekit-activation-********************.js 24.2 kB +6 B (+0.02%)
./dist/assets/js/googlesitekit-ad-blocking-recovery-********************.js 55.5 kB +16 B (+0.03%)
./dist/assets/js/googlesitekit-adminbar-********************.js 35.2 kB +6 B (+0.02%)
./dist/assets/js/googlesitekit-api-********************.js 10.4 kB -2 B (-0.02%)
./dist/assets/js/googlesitekit-components-********************.js 6.46 kB -2 B (-0.03%)
./dist/assets/js/googlesitekit-consent-mode-********************.js 25.6 kB 0 B
./dist/assets/js/googlesitekit-data-********************.js 2.37 kB +1 B (+0.04%)
./dist/assets/js/googlesitekit-datastore-forms-********************.js 9.12 kB -2 B (-0.02%)
./dist/assets/js/googlesitekit-datastore-location-********************.js 2.09 kB 0 B
./dist/assets/js/googlesitekit-datastore-site-********************.js 20.7 kB +5 B (+0.02%)
./dist/assets/js/googlesitekit-datastore-ui-********************.js 10.2 kB 0 B
./dist/assets/js/googlesitekit-datastore-user-********************.js 27.4 kB +3 B (+0.01%)
./dist/assets/js/googlesitekit-entity-dashboard-********************.js 84.6 kB -9 B (-0.01%)
./dist/assets/js/googlesitekit-events-provider-contact-form-7-********************.js 646 B 0 B
./dist/assets/js/googlesitekit-events-provider-easy-digital-downloads-********************.js 977 B 0 B
./dist/assets/js/googlesitekit-events-provider-mailchimp-********************.js 630 B 0 B
./dist/assets/js/googlesitekit-events-provider-ninja-forms-********************.js 717 B 0 B
./dist/assets/js/googlesitekit-events-provider-optin-monster-********************.js 675 B 0 B
./dist/assets/js/googlesitekit-events-provider-popup-maker-********************.js 634 B 0 B
./dist/assets/js/googlesitekit-events-provider-woocommerce-********************.js 1.36 kB 0 B
./dist/assets/js/googlesitekit-events-provider-wpforms-********************.js 633 B 0 B
./dist/assets/js/googlesitekit-i18n-********************.js 4.16 kB 0 B
./dist/assets/js/googlesitekit-main-dashboard-********************.js 156 kB +402 B (+0.26%)
./dist/assets/js/googlesitekit-metric-selection-********************.js 52.5 kB -4 B (-0.01%)
./dist/assets/js/googlesitekit-modules-ads-********************.js 51 kB 0 B
./dist/assets/js/googlesitekit-modules-adsense-********************.js 120 kB +27 B (+0.02%)
./dist/assets/js/googlesitekit-modules-analytics-4-********************.js 195 kB -77 B (-0.04%)
./dist/assets/js/googlesitekit-modules-********************.js 24.1 kB +7 B (+0.03%)
./dist/assets/js/googlesitekit-modules-pagespeed-insights-********************.js 26.4 kB -1 B (0%)
./dist/assets/js/googlesitekit-modules-reader-revenue-manager-********************.js 47.2 kB -29 B (-0.06%)
./dist/assets/js/googlesitekit-modules-search-console-********************.js 70.3 kB +4 B (+0.01%)
./dist/assets/js/googlesitekit-modules-sign-in-with-google-********************.js 32.5 kB -120 B (-0.37%)
./dist/assets/js/googlesitekit-modules-tagmanager-********************.js 33 kB +5 B (+0.02%)
./dist/assets/js/googlesitekit-notifications-********************.js 49.5 kB +18 B (+0.04%)
./dist/assets/js/googlesitekit-polyfills-********************.js 377 B 0 B
./dist/assets/js/googlesitekit-settings-********************.js 129 kB -12 B (-0.01%)
./dist/assets/js/googlesitekit-splash-********************.js 70.1 kB -139 B (-0.2%)
./dist/assets/js/googlesitekit-user-input-********************.js 44.5 kB -3 B (-0.01%)
./dist/assets/js/googlesitekit-vendor-********************.js 313 kB -2 B (0%)
./dist/assets/js/googlesitekit-widgets-********************.js 104 kB +720 B (+0.7%)
./dist/assets/js/googlesitekit-wp-dashboard-********************.js 63.9 kB +4 B (+0.01%)
./dist/assets/js/runtime-********************.js 1.4 kB 0 B

compressed-size-action

Copy link

github-actions bot commented May 16, 2025

Build files for 4b8a565 are ready:

@jimmymadon jimmymadon requested a review from aaemnnosttv May 20, 2025 20:30
Copy link
Collaborator

@aaemnnosttv aaemnnosttv left a comment

Choose a reason for hiding this comment

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

Apologies for the mega comment, but there are some important things to consider that may not have been clear during IBR.

Comment on lines +149 to +157
for ( const viewContext of viewContexts ) {
yield {
type: POPULATE_QUEUE,
payload: {
viewContext,
groupID,
},
};
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

@tofumatt There are a few problems with populating the queue here

  • The queuedNotifications state is only segmented by groupID. The queues are intended to be populated for the viewContext where we are requesting notifications for from the selector. By calling this for all contexts the notification supports, we will effectively populate the queues with all notifications across all viewContexts which would result in the viewContext being ignored as queue groups would be populated with all notifications for that group.
  • Populating the queue at registration time will undermine the way it is ordered, which is intended to run with the full list of registered notifications in order to ensure all of the priorities are considered. Thinking of it iteratively, when we register the first notification, it will populate the queue, and will queue the one and only notification. The same will happen essentially on every subsequent invocation since there will by definition only be one notification that has not been queued yet, so priorities will no longer be considered. We could update it to sort by priority as well, but that would nullify the priority group racing which prioritizes notifications (in the same priority group) which are ready first.
  • Populating the queue on registration will cause checkRequirements to be evaluated in a pre-loaded way rather than on-demand as they should be which could result in some API requests being made too often or when not needed.

The good news though is that I think the solution here is simpler. We should preserve the selector->resolver-based queue population since this is where the current queue is cleared and repopulated on-demand. The only thing we really need to change here is to invalidate the resolver (which can be done for all args in one go) instead. This way, the queue will still be populated at the same time it is today and there is no penalty for invalidating an already invalidated resolver which makes it much less impactful than populating.

The only drawback/challenge I can think of is that this could result in a different queue when repopulated in this way than it had before which would be a poor experience for the user. Perhaps the solution here is to not clear the queues unless the viewContext has changed if already populated. Then when populating the queue, we'd filter out all notifications that are already queued from being re-evaluated for population, but this would mean on-demand notifications would always go to the end of the queue where they may not be seen at all.

Alternatively, we could still clear the queue safely, so long as we preserve the head of each group – that way we'd never be changing the "current"/active notification which is important to avoid disrupting the UX.

Lastly, we need to make sure that runtime side-effects such as marking a notification as "viewed" don't cause it to be rotated out due to changes we're making here that involve re-evaluating the queues.

It sounds like we're running into many of the same challenges we initially identified in the comments on #9453 but I feel like we should be able to make it work by addressing the above. Ultimately, in order to to really have an on-demand notification that will be shown right away that doesn't break existing queues is to decouple it from the existing location (avoid flicker/layout-shift) and groups (avoid disrupting queues/order). Eventually, I think we'll want/need a new N area + N group for snackbar type notifications that float in the corner and allows for multiple to be shown simultaneously. These should be used conservatively but are also an established pattern (i.e. in Gmail when you archive/delete an email). This is out of scope for this issue but something I believe we are aiming for in the future that should compliment the work here rather than invalidate it.

cc: @jimmymadon

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Invalidating the resolver for getQueuedNotifications will cause the already displayed/loaded notifications to be removed (eg. "disappear") for a split-second while they're reloaded though, because resetQueue is called before the queue is repopulated. I wonder if we should refrain from resetting the queue anytime we reload the notifications to prevent any UI bugs here 🤔

Comment on lines 47 to 49
checkRequirements: () => {
return true;
},
Copy link
Collaborator

Choose a reason for hiding this comment

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

checkRequirements is optional and will be treated the same way if not provided

async check() {
if ( checkRequirements ) {
return await checkRequirements( registry );
}
return true;
},

@tofumatt tofumatt changed the title Register-notification-update-9453 Allow notifications to be registered and immediately shown May 30, 2025
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.

2 participants