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

[bug]: Erroneously throwing error #1986

Open
1 task done
moonmeister opened this issue Nov 14, 2024 · 4 comments
Open
1 task done

[bug]: Erroneously throwing error #1986

moonmeister opened this issue Nov 14, 2024 · 4 comments
Assignees
Labels
needs: author response Pending information from the author status: actionable Ready for work to begin type: bug Issue that causes incorrect or unexpected behavior

Comments

@moonmeister
Copy link
Collaborator

Description

We were getting :

Error: useBlocksTheme hook was called outside of context, make sure your app is wrapped with WordPressBlocksProvider

This simply wasn't the case. AS you can se from the _app.js

import "../../faust.config";
import { WordPressBlocksProvider } from "@faustwp/blocks";
import { FaustProvider } from "@faustwp/core";
import "./global.css";
import Layout from "@/components/layout";
import "@faustwp/core/dist/css/toolbar.css";
import blocks from "@/wp-blocks";

export default function MyApp({ Component, pageProps }) {
	return (
		<FaustProvider pageProps={pageProps}>
			<WordPressBlocksProvider config={{ blocks, theme: null }}>
				<Layout>
					<Component {...pageProps} />
				</Layout>
			</WordPressBlocksProvider>
		</FaustProvider>
	);
}

A quick mental check told me I'd recently edited one line in here. Reverting that fixed this issue:

<WordPressBlocksProvider config={{ blocks, theme: undefined }}>

This was strange as in JS these should be practically the same.

Some code seleuthing quickly turned up:

The use of === means we don't type cast null to undefined even if it's practically the same. And allowing null to work while undefined doesn't.

So, being the docs show a prolific use of null to no pass a theme but undefined doesn't work, neither does simply not passing the theme in the config object. Seems like the fundamental issue here is we're checking for the WordPressBlocksProvider based on the value of theme and not wether the WordPressBlocksContext or WordPressThemeContext are actually available

Steps to reproduce

See above

Additional context

related: #1844

@faustwp/core Version

3.1.0

@faustwp/cli Version

3.1.1

FaustWP Plugin Version

na

WordPress Version

na

Additional environment details

@faustwp/[email protected]

Please confirm that you have searched existing issues in the repo.

  • Yes
@josephfusco
Copy link
Member

Note, we are using null in the block-support example

@josephfusco josephfusco added type: bug Issue that causes incorrect or unexpected behavior status: actionable Ready for work to begin labels Nov 14, 2024
@colinmurphy
Copy link
Contributor

I couldn't replicate the issue using https://github.com/wpengine/faustjs/tree/canary/examples/next/block-support but I had some other issues with a missing BlockB type in the template throwing an error for a missing type - https://gist.github.com/colinmurphy/2b97f29bbb90a5214406a32148a8d18e

I will try tomorrow and setup the canary branch and follow the setup tutorial to try and replicate the issue.

@colinmurphy
Copy link
Contributor

@moonmeister I still cannot replicate the issue with a fresh install of Faust. I am using faust/blocks version 5 but that particular function isn't updated between 4.1.0 and the latest version.

I tried the following config changes and these all worked locally.

<WordPressBlocksProvider config={{ blocks, theme: undefined }}>
<WordPressBlocksProvider config={{ blocks, theme: null }}>
<WordPressBlocksProvider config={{ blocks}}>

@josephfusco josephfusco added the needs: author response Pending information from the author label Dec 13, 2024
@colinmurphy
Copy link
Contributor

@moonmeister Can you still replicate the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs: author response Pending information from the author status: actionable Ready for work to begin type: bug Issue that causes incorrect or unexpected behavior
Projects
None yet
Development

No branches or pull requests

3 participants