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

fix(gatsby-transformer-remark): restore behavior of serializing date-like fields to string #11716

Merged
merged 6 commits into from
Feb 12, 2019

Conversation

DSchau
Copy link
Contributor

@DSchau DSchau commented Feb 12, 2019

Description

This PR reverts behavior in gatsby-transformer-remark so that date-like fields are serialized to string. This fixes a bug that some were experiencing where content types with a date string were sorted differently than content types with a date object, e.g. this change will revert the behavior so that the below two posts are sorted the same

---
date: 2019-01-01
---
---
date: "2019-01-01"
---

Note that I do think this was a good change, so we'll want to consider perhaps reverting this and baking in better support in the resolvers for sorting these date fields in the future. But for now--we should revert to avoid breaking people's apps.

Related Issues

Fixes regression in #10924

Copy link
Contributor Author

@DSchau DSchau left a comment

Choose a reason for hiding this comment

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

let node
let actions
let createNodeId
beforeEach(() => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some light refactoring here to make this easier to use in the future

@DSchau
Copy link
Contributor Author

DSchau commented Feb 12, 2019

Also let's hold off on merging until the Azure pipeline/windows test passes. I've seen some weirdness with dates before--so want to make sure we're good to go there!

We're good to go!

Copy link
Contributor

@m-allanson m-allanson left a comment

Choose a reason for hiding this comment

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

LGTM! One small question, but don't let it block you from merging.

})
})

describe(`date formatting`, () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth mentioning here (maybe in comment) that this is only needed because there is bug in gatsby core that doesn't really allow sorting mix of date object and strings?

@@ -23,9 +26,13 @@ describe(`Process markdown content correctly`, () => {
},
}

// Make some fake functions its expecting.
const loadNodeContent = node => Promise.resolve(node.content)
actions = { createNode: jest.fn(), createParentChildLink: jest.fn() }
Copy link
Contributor

Choose a reason for hiding this comment

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

can we do:

let markdownNode
beforeEach(() => { markdownNode = null})
createNode: jest.fn(markdownNode => createNode = node)

to avoid those returns in source? return {} is very confusing to read (without looking at tests)

@DSchau DSchau merged commit 29dee3f into gatsbyjs:master Feb 12, 2019
@DSchau DSchau deleted the gatsby-transformer-remark/date-fix branch February 12, 2019 18:00
cheezenaan added a commit to cheezenaan/blog that referenced this pull request Feb 13, 2019
cheezenaan added a commit to cheezenaan/blog that referenced this pull request Feb 13, 2019
gurpreet-hanjra pushed a commit to gurpreet-hanjra/gatsby that referenced this pull request Feb 14, 2019
…like fields to string (gatsbyjs#11716)

* chore: commit

* chore: get tests failing (intentionally) to then fix

* chore: de-dry

* chore: finish tests

* chore: revert relative import
pragmaticpat pushed a commit to pragmaticpat/gatsby that referenced this pull request Apr 28, 2022
…like fields to string (gatsbyjs#11716)

* chore: commit

* chore: get tests failing (intentionally) to then fix

* chore: de-dry

* chore: finish tests

* chore: revert relative import
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants