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

Incorrect blockGap value when using the useBlockSpacing hook #878

Open
1 task done
asvinb opened this issue Jan 8, 2025 · 1 comment
Open
1 task done

Incorrect blockGap value when using the useBlockSpacing hook #878

asvinb opened this issue Jan 8, 2025 · 1 comment

Comments

@asvinb
Copy link

asvinb commented Jan 8, 2025

Describe the bug

I have a block with a manually set block gap value. However, when using the useBlockSpacing hook to retrieve the block gap, it always returns the value defined in theme.json, ignoring the value explicitly set in the block's attributes.

Steps to Reproduce

  1. Add a block which supports the blockGap property.
  2. Set a specific block gap value
  3. Check the returned values from useBlockSpacing hook, where the blockGap value does not match.

Screenshots, screen recording, code snippet

Image

Environment information

No response

WordPress information

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@nicholasio
Copy link
Member

Thanks for the report, looks like this line should check attributes first.

https://devblogs.microsoft.com/typescript/announcing-typescript-5-8-beta/#checked-returns-for-conditional-and-indexed-access-types

The thing with these useBlock* hooks is that they were initially written to try to infer as much as possible from the generated markup and defaults to theme.json values if there's nothing in the generated markup, but that has caused the code to be a bit convoluted.

The future of the framework will rely only on theme.json and the actual attributes of the block , which should make things much more straightforward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants