gatsby icon indicating copy to clipboard operation
gatsby copied to clipboard

Previews URL don't persist across builds with gatsby-source-wordpress

Open lnikell opened this issue 2 years ago • 13 comments

Preliminary Checks

  • [X] This issue is not a duplicate. Before opening a new issue, please search existing issues: https://github.com/gatsbyjs/gatsby/issues
  • [X] This issue is not a question, feature request, RFC, or anything other than a bug report directly related to Gatsby. Please post those things in GitHub Discussions: https://github.com/gatsbyjs/gatsby/discussions

Description

When you generate preview for a page or post via Wordpress, Gatsby generates a preview URL

screenshot-2022-07-19-21-03-10@2x

Eg.

https://preview-{yoursitename}.gtsb.io/generated-preview-path/post/2171/

This URL is a temporary path.

Based on @KyleAMathews feedback

it needs to create a redirect once there's a real url

https://github.com/gatsbyjs/gatsby/blob/b653c7b32e8b0e82f581f1a4586a819999117734/packages/gatsby-source-wordpress/src/steps/source-nodes/update-nodes/wp-actions/update.js#L392

Reproduction Link

https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-source-wordpress

Steps to Reproduce

  1. Use a gatsby-source-wordpress example
  2. Integrate it with WP and Gatsby Cloud
  3. Create a post and press preview in Wordpress
  4. Copy url
  5. Wait few days or just go to Gatsby Cloud -> CMS Preview and press Restart preview
  6. Open url from step 4, this will result in 404 page

Expected Result

After you press Preview in WP, you should land on the page with a persistent URL that users could share between each other and it will either generate a new preview, or open the latest available version.

Actual Result

Preview url is throwing 404 error after rebuilds, or after some time.

Environment

System:
    OS: macOS 12.4
    CPU: (8) arm64 Apple M1
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.14.0 - /usr/local/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 8.3.1 - /usr/local/bin/npm
  Browsers:
    Chrome: 103.0.5060.114
    Safari: 15.5
  npmPackages:
    gatsby: ^4.7.0 => 4.7.0
    gatsby-alias-imports: ^1.0.6 => 1.0.6
    gatsby-plugin-google-tagmanager: ^4.13.0 => 4.13.0
    gatsby-plugin-image: ^2.9.1 => 2.9.1
    gatsby-plugin-manifest: ^4.9.1 => 4.9.1
    gatsby-plugin-mdx: ^3.9.1 => 3.9.1
    gatsby-plugin-postcss: ^5.9.0 => 5.9.0
    gatsby-plugin-react-helmet: ^5.9.0 => 5.9.0
    gatsby-plugin-sharp: ^4.9.1 => 4.9.1
    gatsby-plugin-sitemap: ^5.9.0 => 5.9.0
    gatsby-plugin-svgr-svgo: ^2.0.0 => 2.0.0
    gatsby-remark-copy-linked-files: ^5.9.0 => 5.9.0
    gatsby-remark-images: ^6.9.1 => 6.9.1
    gatsby-remark-prismjs: ^6.9.0 => 6.9.0
    gatsby-remark-responsive-iframe: ^5.9.0 => 5.9.0
    gatsby-remark-video: ^1.2.5 => 1.2.5
    gatsby-source-filesystem: ^4.9.1 => 4.9.1
    gatsby-transformer-sharp: ^4.9.0 => 4.9.0

Config Flags

No response

lnikell avatar Jul 19 '22 19:07 lnikell

What version of gatsby-source-wordpress are you using?

jackonawalk avatar Jul 20 '22 14:07 jackonawalk

@jacksellwood 6.18.0, but it was the issue for very long time

lnikell avatar Jul 20 '22 17:07 lnikell

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

github-actions[bot] avatar Aug 10 '22 00:08 github-actions[bot]

bump it up, still relevant

lnikell avatar Aug 11 '22 11:08 lnikell

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

github-actions[bot] avatar Sep 01 '22 00:09 github-actions[bot]

The question that needs answered here is it there's a way to get the temporary post ids after the post is actually created. If there is, then the source plugin could create the redirects or it'd be an easy bit of code to copy/paste into your createPages.

KyleAMathews avatar Sep 01 '22 02:09 KyleAMathews

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

github-actions[bot] avatar Sep 21 '22 12:09 github-actions[bot]

The issue still exist. Looking forward for the input from Gatsby team.

lnikell avatar Sep 21 '22 12:09 lnikell

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

github-actions[bot] avatar Oct 12 '22 00:10 github-actions[bot]

@TylerBarnes Hi, maybe you can assist with that issue? or suggest some ideas to fix it.

lnikell avatar Oct 24 '22 11:10 lnikell

As far as I'm aware the issue happens when the cache is cleared. I don't think there's a reasonable way to fix this. The reason it happens is:

  1. Preview urls for new drafts are generated when you press open preview because there's no slug/uri yet in WP, so we need to generate one from the data we do have (the post ID).
  2. When the cache is cleared, on the next build we don't fetch all existing drafts from WP. This is because it could be extremely slow depending on the site to fetch all drafts, when likely only a small subset of those are being used.
  3. On clear cache builds we also don't have the auth token to pull private draft. A short lived & unique auth token is sent from WP to the preview build when "Open Preview" is pressed in the UI.

To fix it we would have to:

  • Add a plugin option for auth tokens with no expiry (this is inherently less secure)
  • Use the auth token from plugin options to fetch all drafts in WP (this would result in slower builds)
  • When a page in Gatsby with a temporary generated url is published and gets a real url in WP, we would need to track that and automatically create redirects, otherwise the urls still wouldn't be persistent as the generated urls would now result in a 404 (getting the logic for this right would be tricky and would add additional complexity to preview which is already fairly complex)

I think the downsides to fixing it are greater than the potential upside

TylerBarnes avatar Oct 24 '22 18:10 TylerBarnes

@TylerBarnes thank you! It’s very sad that there is no work around for this. As I understand that issue exists in every CMS due to current Gatsby architecture. I’m just wondering how other users deal with this, since we get complains about that behavior from different clients.

lnikell avatar Oct 24 '22 18:10 lnikell

@TylerBarnes thank you! It’s very sad that there is no work around for this. As I understand that issue exists in every CMS due to current Gatsby architecture. I’m just wondering how other users deal with this, since we get complains about that behavior from different clients.

@lnikell I'm also experiencing this, first preview is a fresh build that has to install project dependencies not just go through the schema again then further changes work as expected: (Important to note that overall builds are faster than v4 but it would be great if this issue was fixed)

This is on gatsby cloud configured with the wp gatsby plugin.

image

CesarBenavides777 avatar Nov 09 '22 15:11 CesarBenavides777

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 60 days of inactivity. It’s been at least 20 days since the last update here. If we missed this issue or if you want to keep it open, please reply here. As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

github-actions[bot] avatar Nov 30 '22 00:11 github-actions[bot]

Hey again!

It’s been 60 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it. Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to comment on this issue or create a new one if you need anything else. As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community! 💪💜

github-actions[bot] avatar Jan 09 '23 12:01 github-actions[bot]