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

Enable support for React 18, bump Gatsby to v5 #3367

Open
wants to merge 21 commits into
base: release-22.x
Choose a base branch
from

Conversation

bradenmacdonald
Copy link
Contributor

@bradenmacdonald bradenmacdonald commented Dec 16, 2024

Description

We are long overdue for supporting React 18. The challenge is that bumping to React 18 and testing with it on our docs site also requires bumping Gatsby from v4 to v5 and gatsby-plugin-mdx from v3 to v5, which introduces a ton of breaking changes to how Gatsby and MDX work.

These upgrades have been attempted before in #2774 and #2767 but so far nobody has been able to finish the work up. I'm thinking we need to bite the bullet sooner or later and get it sort out.

Deploy Preview

https://deploy-preview-3367--paragon-openedx-v23.netlify.app/

Status

Working:

  • Paragon build (npm run build)
  • Paragon in general (the components on the docs site work as normal - see preview above)
  • Most of the docs site
  • Most lint checks
  • Fully backwards compatible (still supports React 16 & 17)

Not working:

  • Test suite (I have it down to 16 failing tests. Mostly there are just simple changes related to react-testing-library's newer userEvent API, and then the tests will be passing again.)
  • Some "Foundations" pages on the docs site (see below)
  • stylelint is not passing (tons of warnings)

Manual testing

Run the gatsby site locally with the command cd www and rm -rf .cache && NODE_OPTIONS=--max-old-space-size=16384 npm run start

Issues and solutions

  • (NEW) The home page of the docs site lists pages like "Icons" in the Components list ("Layout" appears twice - once as a component and once as a page). TODO
  • Some of the "Foundations" pages (the ones that use MDX, not TSX, like Layout , have errors and aren't loading properly. TODO
  • Some of the "Foundations" pages (the ones that use MDX, not TSX, like Layout , are not rendering with the correct layout. Fixed by @brian-smith-tcril via e0a3539
  • Currently, gatsby is running out of memory when trying to run npm run start. I thought I had solved this with GATSBY_CPU_COUNT=4 (f67d1f7) but it no longer seems to be helping (even if lowered down to 1). I think the memory usage depends on how much has been cached, so clearing the cache always requires a lot more memory. For now the only workaround is to run it with NODE_OPTIONS=--max-old-space-size=16384 npm run start but allocating 16GB each time is not feasible.
    • Note that npm run build-docs seems to be working fine, and the "deploy preview" build of this PR works fine too.
    • Solved! By @brian-smith-tcril who found that adding DEV_SSR/FAST_DEV will avoid the issue.
  • This PR necessarily bumps the version of sass used via transitive dependencies. Will this version bump cause issues for Paragon consumers (if we change the sass code to the new version)? e.g. see 958f617
    • ‼️ help answering this would be appreciated ‼️
  • Upgrading sass means instead of e.g. map-get(...) we are encouraged to use @use "sass:map"; and map.get(...) - done via 958f617 but this may need to be reverted, see question above.
  • Stylelint is not passing - haven't investigated this yet.
  • Test cases need to be updated - started with e.g. c5ca0a5 and 1942f03 but haven't finished
  • Horizontal padding, font sizes, and other minor changes are seen on pages like the Button component docs.
  • Many other sass deprecation warnings related to import etc. have been suppressed for now: 6946d67 we probably can't address this properly without a major bootstrap upgrade
  • GraphQL syntax has changed in some cases, resulting in a bunch of deprecation warnings - solved with 2dd6935
  • The { and < characters must now be escaped in markdown - solved with 0f6004f
  • The childMdx API is no longer available - gatsby-plugin-mdx no longer allows rendering multiple MDX documents in one page. I worked around this by adding react-markdown and rendering the props descriptions as plain markdown (they don't use MDX anyways) - 48aa670
  • Some Gatsby/rehype plugins can only be imported as ESM - so I had to convert the Gatsby config to ESM 60e534c
  • Code blocks in Markdown no longer pass in attributes like live automatically, so I had to add rehype-mdx-code-props in 11b7605
  • Supporting <PropsTable> as an MDX component was tricky because it requires some context from the parent JSX component, which was being inlined as a local variable resulting in lint warnings: "Do not define components during render". It turns out that the props tables in question, on this Data Views page are already present in the usual place at the end of the document anyways. So I think it's more consistent to just remove support for this element from that page (remove the duplicate props tables) and avoid having to re-engineer PropsTable to better support context for this one very questionable use case. Done with c92a1a2
  • update imports for 'renderHook' (now part of @testing-library/react) - 53500ee

@openedx-webhooks
Copy link

Thanks for the pull request, @bradenmacdonald!

What's next?

Please work through the following steps to get your changes ready for engineering review:

🔘 Get product approval

If you haven't already, check this list to see if your contribution needs to go through the product review process.

  • If it does, you'll need to submit a product proposal for your contribution, and have it reviewed by the Product Working Group.
    • This process (including the steps you'll need to take) is documented here.
  • If it doesn't, simply proceed with the next step.

🔘 Provide context

To help your reviewers and other members of the community understand the purpose and larger context of your changes, feel free to add as much of the following information to the PR description as you can:

  • Dependencies

    This PR must be merged before / after / at the same time as ...

  • Blockers

    This PR is waiting for OEP-1234 to be accepted.

  • Timeline information

    This PR must be merged by XX date because ...

  • Partner information

    This is for a course on edx.org.

  • Supporting documentation
  • Relevant Open edX discussion forum threads

🔘 Get a green build

If one or more checks are failing, continue working on your changes until this is no longer the case and your build turns green.

🔘 Let us know that your PR is ready for review:

Who will review my changes?

This repository is currently maintained by @openedx/paragon-working-group. Tag them in a comment and let them know that your changes are ready for review.

Where can I find more information?

If you'd like to get more details on all aspects of the review process for open source pull requests (OSPRs), check out the following resources:

When can I expect my changes to be merged?

Our goal is to get community contributions seen and reviewed as efficiently as possible.

However, the amount of time that it takes to review and merge a PR can vary significantly based on factors such as:

  • The size and impact of the changes that it introduces
  • The need for product review
  • Maintenance status of the parent repository

💡 As a result it may take up to several weeks or months to complete a review and merge your PR.

@openedx-webhooks openedx-webhooks added the open-source-contribution PR author is not from Axim or 2U label Dec 16, 2024
Copy link

netlify bot commented Dec 16, 2024

Deploy Preview for paragon-openedx-v23 ready!

Name Link
🔨 Latest commit c5ca0a5
🔍 Latest deploy log https://app.netlify.com/sites/paragon-openedx-v23/deploys/67608bbcdeb4ce0008d6f3bc
😎 Deploy Preview https://deploy-preview-3367--paragon-openedx-v23.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@bradenmacdonald bradenmacdonald changed the base branch from release-23.x to master December 16, 2024 20:22
@bradenmacdonald bradenmacdonald changed the base branch from master to release-22.x December 16, 2024 22:22
@brian-smith-tcril
Copy link
Contributor

brian-smith-tcril commented Dec 17, 2024

After reading through a ton of gatsbyjs/gatsby#36899 and trying a few things I found gatsbyjs/gatsby#36899 (comment) and managed to get the dev server running.

bsmith@aximdev:~/code/paragon$ git diff
diff --git a/www/gatsby-config.mjs b/www/gatsby-config.mjs
index d0ab6c658e..aaf5daab39 100644
--- a/www/gatsby-config.mjs
+++ b/www/gatsby-config.mjs
@@ -130,4 +130,7 @@ export default {
   // Match the location of the site on github pages if no path prefix is specified
   pathPrefix: process.env.PATH_PREFIX || '',
   plugins,
+  flags: {
+    DEV_SSR: true
+  },
 };

Edit: I looked into this a bit more and found https://www.gatsbyjs.com/docs/reference/release-notes/v2.28/#feature-flags-in-gatsby-configjs. Setting the FAST_DEV flag also works (and seems like a good thing to do!)

@brian-smith-tcril
Copy link
Contributor

Re:

Some of the "Foundations" pages (the ones that use MDX, not TSX, like Layout , are not rendering with the correct layout. Some fix is required (see related work in #2767 which has some code related to this)

With this change

-        default: require.resolve(
-          './src/templates/default-mdx-page-template.tsx',
-        ),

It seems the default-mdx-page-template layout is just not being used at all. I know defaultLayouts were removed in v4, and the migration of component-page-template seems to have gone smoothly, but I'm a little lost as to how to properly migrate the other layout.

…rver

Replaces/reverts "fix: limit parallelization of build to avoid OOM error during 'develop'"
Copy link

netlify bot commented Dec 17, 2024

Deploy Preview for paragon-openedx-v22 ready!

Name Link
🔨 Latest commit e0a3539
🔍 Latest deploy log https://app.netlify.com/sites/paragon-openedx-v22/deploys/6761e57ed4af3200081e9aba
😎 Deploy Preview https://deploy-preview-3367--paragon-openedx-v22.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@bradenmacdonald
Copy link
Contributor Author

It seems the default-mdx-page-template layout is just not being used at all. I know defaultLayouts were removed in v4, and the migration of component-page-template seems to have gone smoothly, but I'm a little lost as to how to properly migrate the other layout.

Yeah, me too. I tried a couple things based on the docs but didn't have much luck yet. There is some perhaps complication from the fact that Gatsby includes everything in src/pages/ by default, but I've also added those pages explicitly using a gatsby-source-filesystem in gatsby-config.mjs because I was seeing some Could not locate File node errors if I didn't include that in the config (though it wasn't needed with the previous version).

Clearly, there is somewhere that we need to specify that default-mdx-page-template should be used, but I haven't found where yet, nor figured out why putting it in www/utils/createPages.js similarly to how #2767 did it isn't working.

@brian-smith-tcril
Copy link
Contributor

So I managed to get the layout page to render, I had to comment some stuff in the .mdx out and there are still a few errors, but it's at least a jumping off point

braden/react-gatsby-bump...5589454

@bradenmacdonald
Copy link
Contributor Author

@brian-smith-tcril Nice! I pulled in most of that change for now. It seems like pages like icons.mdx are now working perfectly, so the layout part is correct - just need to solve the random errors on the other pages.

@bradenmacdonald
Copy link
Contributor Author

bradenmacdonald commented Dec 18, 2024

For some reason, either when I changed the target branch to release-22.x or when I pushed that fix from @brian-smith-tcril, the "v22" deploy preview is now broken and can't load the theme CSS: https://deploy-preview-3367--paragon-openedx-v22.netlify.app/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
open-source-contribution PR author is not from Axim or 2U
Projects
Status: In Eng Review
Development

Successfully merging this pull request may close these issues.

3 participants