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

Fix Faust.js WordPress Plugin Preview #1568

Merged
merged 4 commits into from
Sep 13, 2023

Conversation

josephfusco
Copy link
Member

@josephfusco josephfusco commented Sep 7, 2023

Tasks

  • I have signed a Contributor License Agreement (CLA) with WP Engine.
  • If a code change, I have written testing instructions that the whole team & outside contributors can understand.
  • I have written and included a comprehensive changeset to properly document the changes I've made.

Description

These changes include a proposed fix for #1561.

wp-admin block editor interface showing preview button locations

Testing

  1. Checkout this branch that includes changes to the faustwp plugin: MERL-1205-refactor-custom-preview
  2. Using the updated faustwp plugin, create a new post & save as draft (do not publish)
  3. Observe that both preview links correctly resolve to display draft content

@changeset-bot
Copy link

changeset-bot bot commented Sep 7, 2023

🦋 Changeset detected

Latest commit: caec0a9

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@faustwp/wordpress-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@josephfusco josephfusco changed the title Fixed snackbar but top preview dropdown still breaks Fix Faust.js Preview Sep 7, 2023
@josephfusco josephfusco changed the title Fix Faust.js Preview Fix Faust.js WordPress Plugin Preview Sep 7, 2023
@josephfusco josephfusco added the package: faustwp Related to the companion WordPress plugin label Sep 7, 2023
@github-actions
Copy link
Contributor

github-actions bot commented Sep 7, 2023

📦 Next.js Bundle Analysis for @faustwp/getting-started-example

This analysis was generated by the Next.js Bundle Analysis action. 🤖

This PR introduced no changes to the JavaScript bundle! 🙌

'_faustwp_preview_link',
array(
'_preview_link' => get_preview_post_link(),
'_wp_version' => get_bloginfo( 'version' ),
Copy link
Member Author

Choose a reason for hiding this comment

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

Adding the WordPress version to better handle any breaking changes until WordPress/gutenberg#13998 is resolved.

@josephfusco josephfusco marked this pull request as ready for review September 12, 2023 16:31
@josephfusco josephfusco requested a review from a team as a code owner September 12, 2023 16:31
Signed-off-by: Joe Fusco <[email protected]>
@josephfusco josephfusco force-pushed the MERL-1205-refactor-custom-preview branch from 07466d6 to ffcac01 Compare September 12, 2023 21:38
Signed-off-by: Joe Fusco <[email protected]>
Signed-off-by: Joe Fusco <[email protected]>
Copy link
Contributor

@blakewilson blakewilson left a comment

Choose a reason for hiding this comment

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

Nice @josephfusco! Pulled this down locally and observed it working as expected in Local.

@blakewilson
Copy link
Contributor

@josephfusco Looks like there is a merge conflict. Once this is resolved we can get this merged.

Signed-off-by: Joe Fusco <[email protected]>

# Conflicts:
#	package-lock.json
@josephfusco josephfusco merged commit fcc6d37 into canary Sep 13, 2023
13 checks passed
@josephfusco josephfusco deleted the MERL-1205-refactor-custom-preview branch September 13, 2023 16:44
@blakewilson
Copy link
Contributor

I'm now experiencing some weird behavior with this, and I think it's related to the autosave functionality that no longer exists:

https://github.com/wpengine/faustjs/blame/deb57674d4854e9888883a918e800c276dd26b3a/plugins/faustwp/includes/replacement/previewlinks.js#L45

When previewing now on an existing post/page, it looks like it redirects to the preview page properly, but it is no longer creating an autosave beforehand, so you are not seeing the most recent preview data. If you wait for it to autosave, then you'll of course see it, but the autosave is no longer being generated once the preview button is clicked in my experience.

cc @josephfusco

switch (version) {
default:
return {
headerLink: document.querySelector('.edit-post-header-preview__grouping-external a'),
Copy link
Member

Choose a reason for hiding this comment

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

This query selector can only be used once since we replace the node in line 49 thus making it problematic. If we attempt to read this from a deleted node we may find issues.

// Clone & replace the original link in order to clear pre-existing events.
if (headerLink && headerLink.getAttribute('href') !== faustPreviewLink) {
const clonedHeaderLink = headerLink.cloneNode(true);
headerLink.parentNode.replaceChild(clonedHeaderLink, headerLink);
Copy link
Member

Choose a reason for hiding this comment

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

This cannot work unfortunately. The whole preview box is controlled by React and any attempts to modify the DOM under its nose will result in fatal errors. For example here is the result when I call wp.data.dispatch('core/editor').autosave(); after that:

Screenshot 2023-11-13 at 13 32 12 Screenshot 2023-11-13 at 13 32 08

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
package: faustwp Related to the companion WordPress plugin
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants