ButterCMS / gatsbyjs-starter-buttercms

Drop-in proof-of-concept GatsbyJS app, fully integrated with your ButterCMS account
https://gatsbyjs-starter-buttercms-vercel.vercel.app/
3 stars 8 forks source link

Gatsby Iframe Preview not working #31

Closed ViolanteCodes closed 2 years ago

ViolanteCodes commented 2 years ago

See Video here for demonstration:

https://share.getcloudapp.com/12u0PPPP

prokopsimek commented 2 years ago

@ViolanteCodes Hmm, I guess this will need a discussion. As the content is generated on the Gatsby startup the public URL contains JUST published or ALSO draft according to set environment variable BUTTER_CMS_PREVIEW.

If we'd like to enable loading by query parameter ?preview=1 so we need to remove all dependency on gatsby-starter-buttercms and go with the less secure solution - set the API key in FE code and load these data on the client-side instead of in the time of FE generation. (similar problem like this: https://github.com/ButterCMS/gatsby-applifting/issues/18)

ViolanteCodes commented 2 years ago

@orlyohreally can you comment on how this was handled for nextjs, given that it also uses the .env variable to set previewing?

orlyohreally commented 2 years ago

@prokopsimek The preview parameter in the url could be ignored for Gastby apps. The users should provide URLs of their app with the preview env variable set to true to actually preview draft data in the preview panel. The preview panel should still work for the gatsby app with the preview env variable set to true (or omitted completely) or false

prokopsimek commented 2 years ago

@orlyohreally Since using the gatsby-source-buttercms so I would need to add GQL call directly to React hook useEffect. If you wish so, just let me know. The same issue as this: https://github.com/ButterCMS/gatsby-applifting/issues/18, because of the SSG.

ViolanteCodes commented 2 years ago

@orlyohreally I think we're okay to proceed with the suggested method - is that correct?

orlyohreally commented 2 years ago

@prokopsimek @ViolanteCodes Yes

ViolanteCodes commented 2 years ago

Had to merge this PR into the review-fixes branch to get it to deploy on my vercel (vercel is building off of a fork of the repo right now).

Tried it out, and it appears to be working great with draft post: https://share.getcloudapp.com/DOumlGvb. Landing page is also working. Great job!

prokopsimek commented 2 years ago

Sorry for the discussion in comments. I absolutely misunderstood the root cause.