-
Notifications
You must be signed in to change notification settings - Fork 144
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
Bug: Fixing null/undefined theme argument for the WordPressBlocksProvider #2013
Conversation
…PressBlocksProvider
🦋 Changeset detectedLatest commit: 9059522 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
📦 Next.js Bundle Analysis for @faustwp/getting-started-exampleThis analysis was generated by the Next.js Bundle Analysis action. 🤖 This PR introduced no changes to the JavaScript bundle! 🙌 |
@moonmeister Can you review this please and see if you can still replicate issue #1986 please |
@moonmeister I need to update this PR as some of the logic isn't correct |
@moonmeister This is ready for review. |
Can you explain why/how this fixes the issue? |
What PR should solve is the issue around not allowing null for the theme argument for the WordPressBlockProvider. FWIW I couldn't ever replicate the bug but this is what the PR should do
|
Thank you for help on debugging this issue. I have updated the PR. I have also updated details on how to replicate the issue and also how it appears theme might be a redundant argument. |
… an undefined themeContext error to be thrown for useBlocksTheme function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@colinmurphy I'm guessing we need to leave these tests in now that we've changed the fix, yes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@moonmeister We probably don't. I was leaving this for reference if someone wanted to use the theme argument but I removed the failing test for undefined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@moonmeister Tests reverted back. Thanks for pointing this out.
Just confirming I did some further testing and the following 3 scenarios worked. I just wanted to test again as we will be updating the docs for Faust to remove the theme argument. // src/pages/_app.js
import "@/styles/globals.css";
import { WordPressBlocksProvider } from "@faustwp/blocks";
import blocks from "../wp-blocks";
export default function App({ Component, pageProps }) {
return (
<WordPressBlocksProvider config={{ blocks}}>
<Component {...pageProps} />
</WordPressBlocksProvider>
);
} // src/pages/_app.js
import "@/styles/globals.css";
import { WordPressBlocksProvider } from "@faustwp/blocks";
import blocks from "../wp-blocks";
export default function App({ Component, pageProps }) {
return (
<WordPressBlocksProvider config={{ blocks, theme: null}}>
<Component {...pageProps} />
</WordPressBlocksProvider>
);
} // src/pages/_app.js
import "@/styles/globals.css";
import { WordPressBlocksProvider } from "@faustwp/blocks";
import blocks from "../wp-blocks";
export default function App({ Component, pageProps }) {
return (
<WordPressBlocksProvider config={{ blocks, theme: undefined}}>
<Component {...pageProps} />
</WordPressBlocksProvider>
);
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Tasks
Description
Fixed an issue with the theme argument for the WordPressBlockProvider to allow for null or undefined #1986
The condition to check if WordPressThemeContext is not needed as theme is an optional argument as per our docs - https://faustjs.org/reference/wordpressblocksprovider
e.g.
So setting the theme argument null, undefined or not at all should not result in an error.
How to replicate the issue
If you setup an Next.js app with Faust Blocks you should be able to replicate the error.
src/pages/_app.js
src/pages/index.js
src/wp-blocks/index.js
if you run
npm run dev
you will get the following error:The following PR fixes that issue.
Further Discussion
After debugging this issue with @moonmeister we also found that the theme argument appears to be redundant.
If you have a look at any of the blocks, it is only passed to the getStyles component which doesn't use the theme argument.
e.g.
https://github.com/wpengine/faustjs/blob/canary/packages/blocks/src/blocks/CoreParagraph.tsx
https://github.com/wpengine/faustjs/blob/canary/packages/blocks/src/utils/get-styles/getStyles.ts
https://github.com/wpengine/faustjs/blob/canary/packages/blocks/src/utils/get-styles/getTextStyles.ts#L10
There is a question on whether this is needed as none of the style components use this argument.
Related Issue(s):
#1986
Testing
As described above using a next.js app
Screenshots
Documentation Changes
Dependant PRs