fix(gatsby-plugin-theme-ui): Fast Refresh Compatibility #1659
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.

Description
Hi!
We were looking into the issues listed below and found that we'd need to fix a little thing in Gatsby and also something in Theme UI. Fast Refresh has some limitations (https://www.gatsbyjs.com/docs/reference/local-development/fast-refresh/#limitations) and in the past our docs didn't account for those + the Theme UI plugin is pretty "old" so it used the suggested solutions at the time.
Anyhow, the issue is that the
wrapRootElement/wrapPageElementAPIs in Gatsby are not React components but functions that we call and so in this plugin they pass the lowercased component through. Fast Refresh doesn't like lowercased components so the fix is to 1) use PascalCase for the real react component and 2) use that React component explicitly ingatsby-ssr.js/gatsby-browser.js.While our fix on Gatsby's side of things will make Theme UI work, too, adding these changes here will minimize the React tree that Fast Refresh has to go through. Here's a video:
2021_04_16_3fed8cd9.mp4
As you can see only two files were traversed for the change. And it works, of course 😆
This PR
I've put each change in separate commits for easier reviewing. I essentially applied the changes made to the Gatsby plugin to all other Gatsby instances where that pattern was used.
I also updated the docs and any occurrence of a theme/components to not use anonymous default exports (as Fast Refresh doesn't like that) and it's also better for debugging / profiling.
Related
Fixes #1440
Fixes gatsbyjs/gatsby#30387
Fixes #1595
Version
Published prerelease version:
v0.7.1-develop.0Changelog
🎉 This release contains work from a new contributor! 🎉
Thank you, Jonathan Van Buren (@vanbujm), for all your work!
🐛 Bug Fix
gatsby-plugin-theme-ui@theme-ui/componentsdevelop@theme-ui/editor,gatsby-plugin-theme-ui,@theme-ui/parse-props,@theme-ui/prism,@theme-ui/style-guide@theme-ui/style-guide🔩 Dependency Updates
Authors: 5