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

Live Preview: dismiss sticky notice after activating the theme (season 2) #84730

Merged
merged 4 commits into from
Dec 4, 2023

Conversation

fushar
Copy link
Contributor

@fushar fushar commented Dec 1, 2023

Proposed Changes

This recent PR:

resurfaced a bug which have been previously fixed by:

The fix was subtle, so it can be easily missed. This PR reintroduces the fix, with code comments.

This PR also fixes a bug where we ALWAYS call the theme API (with null ID) event though we're not previewing anything.

Reviewers are encouraged to review commit-by-commit :)

Testing Instructions

  1. Sandbox widgets.wp.com
  2. Patch this PR to your sandbox (install-plugin.sh wpcom-block-editor live-preview-broken-activate)
  3. Live-preview a theme, then activate it.
  4. Verify that the sticky notice is dismissed.
  5. Reminder: you might have to Disable Cache so that the right code is pulled from widgets.wp.com.

Pre-merge Checklist

  • Has the general commit checklist been followed? (PCYsg-hS-p2)
  • https://wpcalypso.wordpress.com/devdocs/docs/testing/index.md for your changes?
  • Have you tested the feature in Simple (P9HQHe-k8-p2), Atomic (P9HQHe-jW-p2), and self-hosted Jetpack sites (PCYsg-g6b-p2)?
  • Have you checked for TypeScript, React or other console errors?
  • Have you used memoizing on expensive computations? More info in Memoizing with create-selector and Using memoizing selectors and Our Approach to Data
  • Have we added the "[Status] String Freeze" label as soon as any new strings were ready for translation (p4TIVU-5Jq-p2)?
  • For changes affecting Jetpack: Have we added the "[Status] Needs Privacy Updates" label if this pull request changes what data or activity we track or use (p4TIVU-ajp-p2)?

@fushar fushar requested a review from a team December 1, 2023 02:59
@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Dec 1, 2023
Copy link

github-actions bot commented Dec 1, 2023

@matticbot
Copy link
Contributor

This PR modifies the release build for the following Calypso Apps:

For info about this notification, see here: PCYsg-OT6-p2

  • wpcom-block-editor

To test WordPress.com changes, run install-plugin.sh $pluginSlug live-preview-broken-activate on your sandbox.

@matticbot
Copy link
Contributor

This PR does not affect the size of JS and CSS bundles shipped to the user's browser.

Generated by performance advisor bot at iscalypsofastyet.com.

// Subscribe to the core store, so that previewingThemeSlug can be updated when the theme is activated.
// We need this hack because the currentlyPreviewingTheme() function is not a hook.
select( 'core' );
return currentlyPreviewingTheme();
Copy link
Contributor

Choose a reason for hiding this comment

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

We use isResolving( 'activateTheme' ) to check whether the previewing theme is activating. Maybe we can use the same trick?

In addition, Gutenberg uses history.replace to update the query striing. Therefore, I guess we can use the location returned by the useLocation hook to detect the changes.

WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We use isResolving( 'activateTheme' ) to check whether the previewing theme is activating. Maybe we can use the same trick?

Could you elaborate the trick? isResolving is a selector from the core store, which we already subscribe here 😄

In addition, Gutenberg uses history.replace to update the query striing. Therefore, I guess we can use the location returned by the useLocation hook to detect the changes.

I also considered this but it requires @wordpress/router, which is not installed by the wpcom-block-editor currently. Does it make sense to add this package for this purpose?

Copy link
Member

Choose a reason for hiding this comment

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

I do not fully understand Arthur's intended meaning, but, for reference, I'm sharing the PR that started using isResolving( 'activateTheme' ). 🙂 WordPress/gutenberg#55658

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you elaborate the trick? isResolving is a selector from the core store, which we already subscribe here 😄

Instead of subscribing the core store, we can subscribe that value to trigger the update. Subscribing the core store may trigger the update all the time 🤔

Does it make sense to add this package for this purpose?

I think it's fine 🙂

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 checked with @arthur791004 and we verified that the current code is fine: it will trigger updates (e.g. rerender) when the value that's returned by useSelect() (i.e., previewingThemeSlug) changes, which is exacly what we want 😄

I looked into @wordpress/router again, but it looks like useLocation() is a private API, which needs unlocking. I think we don't need this complication for now!

Copy link
Member

@okmttdhr okmttdhr left a comment

Choose a reason for hiding this comment

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

Sorry for reintroducing the bug and thank you for fixing it!

I'm approving this PR but I'm curious about Arthur's idea. #84730 (comment)

// Subscribe to the core store, so that previewingThemeSlug can be updated when the theme is activated.
// We need this hack because the currentlyPreviewingTheme() function is not a hook.
select( 'core' );
return currentlyPreviewingTheme();
Copy link
Member

Choose a reason for hiding this comment

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

I do not fully understand Arthur's intended meaning, but, for reference, I'm sharing the PR that started using isResolving( 'activateTheme' ). 🙂 WordPress/gutenberg#55658

@fushar fushar force-pushed the live-preview-broken-activate branch from f3c4a4a to 29ed5b4 Compare December 4, 2023 04:05
Copy link
Contributor

@arthur791004 arthur791004 left a comment

Choose a reason for hiding this comment

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

Nice 👍

@fushar fushar force-pushed the live-preview-broken-activate branch from 29ed5b4 to a382468 Compare December 4, 2023 05:45
@fushar fushar merged commit fba40b1 into trunk Dec 4, 2023
12 checks passed
@fushar fushar deleted the live-preview-broken-activate branch December 4, 2023 06:10
@github-actions github-actions bot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Dec 4, 2023
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.

4 participants