From c86b90b33ab52f906817c70ee3b7cf5f88272db9 Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Thu, 26 Aug 2021 15:25:59 -0700 Subject: [PATCH 1/4] fix: content sync issues (#188) * only override preview link when not doing gql requests * remove attempt to grab existing manifest id's. this results in outdated id's * Update CHANGELOG.md --- CHANGELOG.md | 5 +++ src/Admin/Preview.php | 77 +++++-------------------------------------- 2 files changed, 13 insertions(+), 69 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 476193b..49b626a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## Upcoming fixes + +- The uri field was being overwritten during GraphQL requests, resulting in post uri's that included the content sync URL. +- Some logic attempting to choose the correct manifest ID instead of regenerating it was causing manifest id's to be outdated during previews. + ## 1.1.2 - Fixed redirection to Gatsby Cloud Content Sync preview loader in Gutenberg diff --git a/src/Admin/Preview.php b/src/Admin/Preview.php index 9bc598f..fec5ade 100644 --- a/src/Admin/Preview.php +++ b/src/Admin/Preview.php @@ -23,8 +23,14 @@ function() { ); $use_cloud_loader = self::get_setting( 'use_gatsby_content_sync' ); - - if ( $use_cloud_loader === 'on' ) { + + if ( + $use_cloud_loader === 'on' && + // don't do this during graphql requests + // because that could override the post URI + // in Gatsby! meaning the content sync url could be added to the page path in Gatsby if pages are created from the uri. + ! ( defined( 'GRAPHQL_REQUEST' ) && true === GRAPHQL_REQUEST ) + ) { add_filter( 'preview_post_link', function( $link, $post ) { return self::get_gatsby_content_sync_url_for_post( $post ); }, 10, 2 ); @@ -33,73 +39,6 @@ function() { } public static function get_preview_manifest_id_for_post( $post ) { - $graphql_single_name = - get_post_type_object( $post->post_type ) - ->graphql_single_name; - - if ( !$graphql_single_name || $graphql_single_name === "" ) { - // if we don't have a graphql single name - // Gatsby can't use this post anyway. - // No need to return a manifest - return null; - } - - $action_monitor_posts = new \WP_Query( [ - 'post_type' => 'action_monitor', - 'post_status' => 'any', - 'posts_per_page' => 1, - 'no_found_rows' => true, - 'fields' => 'ids', - 'tax_query' => [ - 'relation' => 'AND', - [ - 'taxonomy' => 'gatsby_action_ref_node_dbid', - 'field' => 'name', - 'terms' => sanitize_text_field( $post->ID ), - ], - [ - 'taxonomy' => 'gatsby_action_ref_node_type', - 'field' => 'name', - 'terms' => sanitize_text_field( $graphql_single_name ), - ], - [ - 'taxonomy' => 'gatsby_action_stream_type', - 'field' => 'name', - 'terms' => 'PREVIEW', - ] - ], - ] ); - - if ( - isset( $action_monitor_posts->posts ) - && ! empty( $action_monitor_posts->posts ) - ) { - $action_monitor_post_id = $action_monitor_posts->posts[0]; - $referenced_node_preview_data = get_post_meta( - $action_monitor_post_id, - '_gatsby_preview_data', - true - ); - - $preview_data = false; - - if ( - $referenced_node_preview_data - && $referenced_node_preview_data !== "" - ) { - $preview_data = json_decode( $referenced_node_preview_data ); - } - - if ( - $preview_data - && property_exists( $preview_data, 'manifestIds' ) - && count( $preview_data->manifestIds ) > 0 - ) { - return $preview_data->manifestIds[0]; - } - } - - // if the above doesn't return a value we generate a new manifest ID from the post_modified date and post db id $revision = self::getPreviewablePostObjectByPostId( $post->ID ); $revision_modified = $revision->post_modified ?? null; From 2bd6b5460d5d7fbe227be41f8ffb0e92abad83b3 Mon Sep 17 00:00:00 2001 From: Tyler Barnes Date: Thu, 26 Aug 2021 15:29:17 -0700 Subject: [PATCH 2/4] release v1.1.3 --- CHANGELOG.md | 2 +- readme.txt | 2 +- wp-gatsby.php | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 49b626a..93601eb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Change Log -## Upcoming fixes +## 1.1.3 - The uri field was being overwritten during GraphQL requests, resulting in post uri's that included the content sync URL. - Some logic attempting to choose the correct manifest ID instead of regenerating it was causing manifest id's to be outdated during previews. diff --git a/readme.txt b/readme.txt index 2dff557..c7ead14 100644 --- a/readme.txt +++ b/readme.txt @@ -4,7 +4,7 @@ Tags: Gatsby, GatsbyJS, JavaScript, JAMStack, Static Site generator, GraphQL, He Requires at least: 5.4.2 Tested up to: 5.6 Requires PHP: 7.3 -Stable tag: 1.1.2 +Stable tag: 1.1.3 License: GPLv3 License URI: https://www.gnu.org/licenses/gpl-3.0.html diff --git a/wp-gatsby.php b/wp-gatsby.php index eb17b46..4f0130f 100644 --- a/wp-gatsby.php +++ b/wp-gatsby.php @@ -2,7 +2,7 @@ /** * Plugin Name: WP Gatsby * Description: Optimize your WordPress site to be a source for Gatsby sites. - * Version: 1.1.2 + * Version: 1.1.3 * Author: GatsbyJS, Jason Bahl, Tyler Barnes * Author URI: https://gatsbyjs.org * Text Domain: wp-gatsby @@ -103,7 +103,7 @@ private function setup_constants() { // Plugin version. if (! defined('WPGATSBY_VERSION') ) { - define('WPGATSBY_VERSION', '1.1.2'); + define('WPGATSBY_VERSION', '1.1.3'); } // Plugin Folder Path. From da48aff80e3a3ff17bca0c09a556187f23332fa4 Mon Sep 17 00:00:00 2001 From: zambolin Date: Tue, 31 Aug 2021 14:02:42 -0400 Subject: [PATCH 3/4] Add REST_REQUEST check. --- src/ActionMonitor/Monitors/PostMonitor.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/ActionMonitor/Monitors/PostMonitor.php b/src/ActionMonitor/Monitors/PostMonitor.php index 76eaa45..127a01c 100644 --- a/src/ActionMonitor/Monitors/PostMonitor.php +++ b/src/ActionMonitor/Monitors/PostMonitor.php @@ -58,6 +58,10 @@ public function callback_transition_post_status( $new_status, $old_status, WP_Po return; } + if(defined("REST_REQUEST") && REST_REQUEST) { + return; + } + // If the object is not a valid post, ignore it if ( ! is_a( $post, 'WP_Post' ) ) { return; From c6c15452347ab10bb6559483bf0ba6f3bf04ac7e Mon Sep 17 00:00:00 2001 From: zambolin Date: Fri, 15 Oct 2021 14:15:28 -0400 Subject: [PATCH 4/4] Update formatting. --- src/ActionMonitor/Monitors/PostMonitor.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ActionMonitor/Monitors/PostMonitor.php b/src/ActionMonitor/Monitors/PostMonitor.php index 127a01c..0066f15 100644 --- a/src/ActionMonitor/Monitors/PostMonitor.php +++ b/src/ActionMonitor/Monitors/PostMonitor.php @@ -58,7 +58,7 @@ public function callback_transition_post_status( $new_status, $old_status, WP_Po return; } - if(defined("REST_REQUEST") && REST_REQUEST) { + if ( defined( 'REST_REQUEST' ) && REST_REQUEST ) { return; }