Problem/Motivation

After upgrading to Gatsby v4 and "drupal/gatsby": "^2.0.0-beta2" I can't get the preview server to refresh.

Steps to reproduce

I'm setting the following config to the same values:

$config['gatsby.settings']['server_url']
$config['gatsby.settings']['preview_callback_url']

Clicking on preview button opens blank page.

Discussion in slack: https://drupal.slack.com/archives/CDQC1MDU6/p1643851291269169

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

Comments

apmsooner created an issue. See original summary.

apmsooner’s picture

Possible related issue noted here regarding preview button functionality with --2 being added to id of preview button: https://drupal.slack.com/archives/CDQC1MDU6/p1643850389402169

This code would fail:

$("#edit-gatsby-preview").on("click", function (e) {

Possibly related to: https://www.drupal.org/project/drupal/issues/3254328

scottalan’s picture

@ampsooner The issue you referenced only relates to the "Gatsby Preview Button" functionality. The preview button can be added to the node form to help content editors get to the preview url.

This is unrelated to this issue in which the preview server is never actually being triggered for a refresh.

scottalan’s picture

I'm doing some debug this morning and gatsbyUpdate() is never called. I grepped the module to confirm and in fact nothing calls this method. If I'm not mistaken, without a call to this method it never calls triggerRefresh(). Thoughts?

I have to be missing something...right? How does the module trigger a refresh without a call to these methods? I guess I expected to see something like this from 1.0-rc6 https://git.drupalcode.org/project/gatsby/-/blob/8.x-1.0-rc6/gatsby.modu...

On hook_entity_{insert,update}() in 1.0-rc6 the data is prepared (gatsbyPrepareData()), then via a shutdown function gatsbyUpdate() is called and then, triggerRefresh().

Yes, I'm linking to 1.0-rc6 but the same should apply to all methods in 2.0.0-beta2.

edit: Looks like the "refresh" should occur here https://git.drupalcode.org/project/gatsby/-/blob/2.0.0-beta2/src/Control... but guessing this is only if fastBuilds is enabled? Since I can't get gatsby develop to complete with fastBuilds enabled maybe that why I'm never seeing a refresh.

damienmckenna’s picture

Priority: Major » Critical
damienmckenna’s picture

Status: Active » Needs review
StatusFileSize
new994 bytes

Does this solve the problem?

damienmckenna’s picture

StatusFileSize
new2.66 KB

The data submission / trigger has two parts.

damienmckenna’s picture

StatusFileSize
new494 bytes
new3.14 KB

The fastbuilds sync path had been changed by accident.

damienmckenna’s picture

damienmckenna’s picture

I've committed #8, please test out the dev version so we can see if there's anything else missing. Thank you.

matt.hood’s picture

I am still running into issues here, with the patches applied Gatsby now recognizes what updates are made and there are no more preview build errors. However the data in the previews, as well as data on the site are not being updated during fastbuilds. Full builds have to be run for site updates to be seen and previews are not being updated at all for some reason.

damienmckenna’s picture

Status: Needs review » Needs work
damienmckenna’s picture

Via the logging I'm adding in #3263887: Add logging for requests to the fastbuild sync endpoint I've identified that Gatsby requests entities modified since a certain millisecond timestamp, whereas Drupal only uses the regular timestamp that works from the seconds.

damienmckenna’s picture

The milliseconds problem related to using a custom branch of gatsby-plugin-drupal that was very out of date.

It now says:

warning The updated node was empty. The fact you're seeing this warning means there's probably a bug in how we're creating and processing updates from Drupal.

damienmckenna’s picture

More testing. On my Gatsby project I had added gatsby-source-drupal ^4.0.0, but that's an old release that went with Gatsby 3; the latest that works with Gatsby 4 is 5.8.0.

I have it working to the point that a Fastbuilds request comes in and a structure like the following is returned for an unpublished node:

Request: 1645550734
JSON: {
  "timestamp":"1645551893",
  "entities": [
    {
      "id":"8dd2bb04-1231-454d-abc4-123123",
      "action":"update",
      "langcode":"en",
      "attributes":@"langcode":"en",
      "drupal_internal__revision_id":"97"
    }
  ]
}

Gatsby Cloud then says:

The updated node was empty. The fact you're seeing this warning means there's probably a bug in how we're creating and processing updates from Drupal.

undefined
damienmckenna’s picture

So the problem appears to be the "attributes" structure that should be a nested array instead of whatever mucked up structure is coming out.

damienmckenna’s picture

Should we use JSON_FORCE_OBJECT in the json_encode() call?

damienmckenna’s picture

Status: Needs work » Fixed

This appears to have been fixed via other issues, if you spot further problems please open new issues and we'll work through them. Thank you.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.