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

[WNMGDS-3243] Upgraded Gatsby to v5 #3477

Merged
merged 17 commits into from
Mar 19, 2025

Conversation

kim-cmsds
Copy link
Collaborator

Summary

  • Jira Tickets (WNMGDS-3243 and WNMGDS-3285)
  • Upgraded the Docs Site to Gatsby version 5 and the related plugin dependencies to their latest versions
  • Gatsby config files are now written in ESM to support github-flavored markdown via remark-gfm now that gatsby-plugin-mdx no longer has support for that type of markdown baked in.
  • Various changes to mdx to account for mdx.js's adding an additional <p> tag around new lines with something called interleaving

How to test

  1. Pull down the branch and run npm install
  2. Run npm run start
  3. Compare the docs site to the one deployed to production

Checklist

  • Prefixed the PR title with the Jira ticket number as [WNMGDS-####] Title or [NO-TICKET] if this is unticketed work.
  • Selected appropriate Type (only one) label for this PR, if it is a breaking change, label should only be Type: Breaking
  • Selected appropriate Impacts, multiple can be selected.
  • Selected appropriate release milestone

@kim-cmsds kim-cmsds added Type: Internal This item relates to internal tooling/maintenance Impacts: Documentation Indicates that this item relates to documentation labels Mar 17, 2025
@kim-cmsds kim-cmsds added this to the 12.2.0 milestone Mar 17, 2025
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The next set of markdown file changes have to do with preventing Interleaving

@@ -4,10 +4,29 @@ order: 70
intro: System color tokens are the entire set of color tokens from which our themes are built.
---

import ColorContrastGuidelines from '../../src/reusable-text-snippets/ColorContrastGuidelines.mdx';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I wasn't able to recreate this functionality in Gatsby v5, so instead of using the reusable text snippet, I've gone ahead and copied and pasted the contents into this markdown file, plus the other three locations where the content was changed. Another option would be to create a react component and import it accordingly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think the React component approach makes the most sense. Do you agree?

If so, we can spin up a ticket for that work.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

<PrintIcon ariaHidden={false} className="ds-u-margin-right--1" />
Print
</Button>
<Button variation="ghost" size="small"><PrintIcon ariaHidden={false} className="ds-u-margin-right--1" />Print</Button>
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These changes prevent interleaving, which affects the generated output and visual display

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh, (I think) it's possible that someone could have auto formatting enabled in their IDE that wraps content to new lines on save or something. We should spin up a new confluence page documenting the nuts and bolts of the Doc Site so we can refer to why we need these things on one line and other miscellany.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@jack-ryan-nava-pbc that's a good call! The latest commit (de66bb7) runs the repository's prettier settings against the markdown file changes

export const onCreateNode = ({ node, getNode, actions }) => {
const { createNodeField } = actions;
if (node.internal.type === `Mdx`) {
const slug = createFilePath({ node, getNode, basePath: `pages`, trailingSlash: false });
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We no longer get slug creation for free and need to apply it to each note

title
}
fields {
slug
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

slug is no longer "top-level"

@@ -55,7 +54,10 @@ const CodeWithSyntaxHighlighting = ({
// for preformatted text that has code as it's child, set language class on <pre> too
// this allows scrolling in code block on small screens
const PreformattedWithLanguageClass = (props: any) => {
if (props.children?.props?.mdxType === 'code' && props.children?.props?.className) {
if (
props.children?.type?.name === 'CodeWithSyntaxHighlighting' &&
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

this type changed and ensures styling for code blocks is unchanged

@@ -1,7 +1,6 @@
import Prism from 'prismjs';
import { ThirdPartyExternalLink } from '@cmsgov/design-system';

import { MDXRenderer } from 'gatsby-plugin-mdx';
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

MDXRenderer is no longer available as part of gatsby-plugin-mdx at version 2 and higher


createPage({
path: originalPage.path,
component: `${originalPage.component}?${contentFilePath}`,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This component argument ensures that the template .tsx file is "linked" to the content that is defined by contentFilePath. The "gatsby-plugin-mdx" plugin will then convert the markdown to HTML/CSS/JS that can be accessed with the children prop within the template component.

},
} = edge;
// Path for this page -- the slug with positioning markers removed
const path = edge.node.fields.slug.replace(/\d+_/g, '');
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there ever a chance a slug might be missing, and should we check for it before processing? My assumption is no, since we create slugs for each Mdx node in onCreateNode, which presumably runs before this. Just checking my understanding of how these steps fit together.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@tamara-corbalt good question!

It's possible to explore the created nodes using the GraphiQL endpoint (http://localhost:8000/___graphql) when running npm run start and verify that the slugs and titles exist using this query.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

All the slugs were created as intended as part of the earlier step onCreateNode (docs api reference)!

@@ -12,8 +12,9 @@ import { Alert } from '@cmsgov/design-system';
<ThemeContent neverThemes={['medicare']}>
<Alert variation="error">
<p class="ds-c-alert__text">
This component is only used for Medicare. Please use the theme switcher to view the component
with Medicare styles.
{
Copy link
Collaborator

@jack-ryan-nava-pbc jack-ryan-nava-pbc Mar 19, 2025

Choose a reason for hiding this comment

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

Ok, so the brackets prevent a second <p> tag from being interleaved within the other <p> tag?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, that's correct

@@ -180,19 +180,19 @@ Align columns horizontally or vertically using [flexbox utility classes](/utilit
</div>
<div
class="ds-l-row ds-u-align-items--start ds-u-border--1 ds-u-padding--1 ds-u-margin-y--2"
style="height: 100px"
style={{ height: 100 }}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The lack of units here makes me nervous. PX is the default?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, PX is the default

{' '}
.ds-u-display--inline-flex{' '}
</code>
<code class="ds-u-display--block ds-u-padding--1 ds-u-margin-bottom--2 utility-example"> .ds-u-display--block </code>
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is so much better than the interpolated spaces. Thank you!

@@ -72,7 +72,7 @@ export const TableOfContentsFeedback = ({ slug }: TableOfContentsFeedbackProps)
<li>
<a
onClick={linkAnalytics}
href={`https://github.com/CMSgov/design-system/edit/main/packages/docs/content/${slug}.mdx`}
href={`https://github.com/CMSgov/design-system/edit/main/packages/docs/content${slug}.mdx`}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the / in the slug itself or is content not a folder anymore?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

the / is in the slug now

sendViewEvent(analyticsPayload);
}
}, []);
import useSendViewEvent from '../helpers/useSendViewEvent';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice! Thank you for extracting this.

@@ -0,0 +1,182 @@
import express from 'express';
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd love (another) walkthrough of these changes!

Copy link
Collaborator

@jack-ryan-nava-pbc jack-ryan-nava-pbc left a comment

Choose a reason for hiding this comment

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

I think I need a walkthrough of the gatsby-node file changes, but pretty much everything else looks a-ok!

Copy link
Collaborator

@jack-ryan-nava-pbc jack-ryan-nava-pbc left a comment

Choose a reason for hiding this comment

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

Walked through changes in call on 3/19/2025 Looks good!

@kim-cmsds kim-cmsds merged commit 1001cfb into jryan/react-18-upgrade Mar 19, 2025
1 check failed
@kim-cmsds kim-cmsds deleted the kcn/WNMGDS-3243/upgrade-gatsby branch March 19, 2025 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Impacts: Documentation Indicates that this item relates to documentation Type: Internal This item relates to internal tooling/maintenance
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants