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

Protect against undefined content in Preview #146

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Protect against undefined content in Preview #146

wants to merge 3 commits into from

Conversation

ax-vasquez
Copy link

@ax-vasquez ax-vasquez commented Dec 18, 2020

In Gatsby Cloud's Preview, all content changes are picked up by the extension. This means that newly-created posts will be sent to Gatsby before the user has had a chance to add all required fields. Repositories for sites meant to be in use with Gatsby Preview should protect all references to required fields so that the site can handle missing elements gracefully.

Changelog

  • Protect against undefined content in Preview
  • Sync shared dependencies to the same versions used in the userland repo
  • Exclude dotenv files from commits
  • Fix environment loading logic
    • Only use CONTENTFUL_DELIVERY_TOKEN when CONTENTFUL_HOST is defined
    • Holding off on this change - We, at Gatsby, likely need to adjust our use of the environment variables - opened a dialog with product team internally to get more info here
  • Add prettier as dev dependency and .prettierrc file with same settings as those in the userland repo
  • Add format script to format code to that of the same settings used in the userland repo

gatsby-config.js Outdated
@@ -23,7 +23,7 @@ const contentfulConfig = {
// To change back to the normal CDA, remove the CONTENTFUL_HOST variable from your environment.
if (process.env.CONTENTFUL_HOST) {
contentfulConfig.host = process.env.CONTENTFUL_HOST;
contentfulConfig.accessToken = process.env.CONTENTFUL_PREVIEW_ACCESS_TOKEN;
contentfulConfig.accessToken = process.env.CONTENTFUL_DELIVERY_TOKEN;
Copy link
Contributor

Choose a reason for hiding this comment

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

You invert the logic users are used to:

If you have no host, we assume you want it from CDA (content delivery)

If you set a host, we assume you set it to CPA (content preview)

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe change the way you set your environment variables?

Copy link
Author

Choose a reason for hiding this comment

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

Thanks! I'll bring this up with the team and see what they suggest 👍

Copy link
Author

Choose a reason for hiding this comment

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

I've reverted this change for now, but am leaving this comment unresolved until I get some feedback from our product team regarding the environment variable change.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

src/components/article-preview.js Outdated Show resolved Hide resolved
src/templates/blog-post.js Outdated Show resolved Hide resolved
src/templates/blog-post.js Outdated Show resolved Hide resolved
@axe312ger
Copy link
Contributor

axe312ger commented Dec 23, 2020

I'd like to have the userland version and this one aligned, at least on dependency/codestyle level.

Feel free to contact me in #gatsby-contentful in your Slack :)

(Talking about contentful-userland/gatsby-contentful-starter#90 which happened in parallel)

@ax-vasquez
Copy link
Author

ax-vasquez commented Jan 4, 2021

I'd like to have the userland version and this one aligned, at least on dependency/codestyle level.

Feel free to contact me in #gatsby-contentful in your Slack :)

(Talking about contentful-userland/gatsby-contentful-starter#90 which happened in parallel)

@axe312ger I believe I addressed all of your feedback with the exception of the environment variable question (though, I did revert the change - I'm simply trying to make sure our understanding is in alignment with how you intend for us to use them 👍 )

With that said, I've since implemented:

  • Optional chaining in spots that could break the Gatsby Preview when the field is undefined
  • Set shared dependencies to the same versions as those used in the userland repo
  • Add prettier as dev dependency and .prettierrc file with same settings as those in the userland repo
  • Add format script to format code to that of the same settings used in the userland repo

@ax-vasquez ax-vasquez requested a review from axe312ger January 4, 2021 19:06
@ax-vasquez
Copy link
Author

@axe312ger , could I get another review on this? 🙂

I believe I addressed all of the feedback, but will certainly be happy to make changes as necessary 👍

Copy link
Contributor

@axe312ger axe312ger left a comment

Choose a reason for hiding this comment

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

If you reduce your PR to the actually purpose of protecting from rendering undefined content, I happily give ✅

But please avoid adding extra unrelated stuff to a PR. Makes it hard to read, review and maintian.

@@ -1,11 +1,11 @@
const spaceImport = require("contentful-import");
Copy link
Contributor

Choose a reason for hiding this comment

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

While I basically agree with single quote over double quote, please do not reformat these files within this PR.

@@ -1,30 +1,30 @@
const chalk = require("chalk");
Copy link
Contributor

Choose a reason for hiding this comment

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

please don't change this in here, make a separate PR

@@ -0,0 +1,6 @@
{
Copy link
Contributor

Choose a reason for hiding this comment

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

its nice to add prettier, but thats unrelated to protect against undefined

Please remove these changes and make a separate PR

@@ -45,6 +46,7 @@
"postinstall": "node ./bin/hello.js",
"setup": "node ./bin/setup.js",
"netlify:login": "netlify login",
"netlify:deploy": "netlify deploy -d public -p"
"netlify:deploy": "netlify deploy -d public -p",
"format": "prettier --write 'src/**/*.js' 'bin/*.js'"
Copy link
Contributor

@axe312ger axe312ger Jan 14, 2021

Choose a reason for hiding this comment

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

Same here. All upgrades and adding prettier are unrelated to your PR

Copy link
Author

Choose a reason for hiding this comment

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

I know - I was confused as to why I needed to add styling stuff (per your comment above), but maybe I am misunderstanding?

What did you mean when you said:

I'd like to have the userland version and this one aligned, at least on dependency/codestyle level.

It sounded to me like you wanted me to implement the same code style settings as that userland repo PR, but I'm not really sure what the intent was 😅 I'll standby for feedback!

@axe312ger
Copy link
Contributor

So if we remove the formatting of unrelated files and you settle the env variable question, lets merge this.

Feel free to contact me in slack via #gatsby-contentful channel

@ax-vasquez
Copy link
Author

If you reduce your PR to the actually purpose of protecting from rendering undefined content, I happily give

But please avoid adding extra unrelated stuff to a PR. Makes it hard to read, review and maintian.

Sorry, misunderstood what you meant when you asked for us to align this PR with the codestyle of the userland repo. I simply used the settings for that project. I'll go through this soon and get it fixed.

This is the comment I am referring to:

"I'd like to have the userland version and this one aligned, at least on dependency/codestyle level."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants