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-plugin-mdx): timeToRead returns NaN when word count is undefined #30489

Merged
merged 1 commit into from
Mar 26, 2021

Conversation

JobenM
Copy link
Contributor

@JobenM JobenM commented Mar 26, 2021

Description

It's possible to have an mdx components without words for example we sometimes have embedded videos/ youtube.

So in this use case the getCounts function returns words property of undefined because the AST visitor never hits a word/paragraph. Thus the calculation for timeToRead (Math.round(words / avgWPM)) returns NaN.

I propose we fallback to 0 for these properties returned in getCounts and then timeToRead can default to 1.

Related Issue

#30490

@gatsbot gatsbot bot added the status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer label Mar 26, 2021
@vladar vladar added topic: MDX and removed status: triage needed Issue or pull request that need to be triaged and assigned to a reviewer labels Mar 26, 2021
Copy link
Contributor

@vladar vladar left a comment

Choose a reason for hiding this comment

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

Looks like a pretty safe change 👍 Thank you!

@vladar vladar merged commit 75e234a into gatsbyjs:master Mar 26, 2021
@vladar
Copy link
Contributor

vladar commented Mar 26, 2021

Will be published in gatsby-plugin-mdx@2.2.0 next Tuesday.

@JobenM
Copy link
Contributor Author

JobenM commented Mar 27, 2021

Will be published in gatsby-plugin-mdx@2.2.0 next Tuesday.

Great news. Thanks @vladar

@axe312ger
Copy link
Collaborator

Thank you!

vladar pushed a commit that referenced this pull request Mar 30, 2021
vladar added a commit that referenced this pull request Mar 30, 2021
…30489) (#30563)

(cherry picked from commit 75e234a)

Co-authored-by: Joe Milne <joekmilne@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants