Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Handle missing class attribute inside wp-class #149

Merged

Conversation

DAreRodz
Copy link
Collaborator

@DAreRodz DAreRodz commented Feb 14, 2023

What

Fixes a bug while hydrating wp-class directives. It happens when the class attribute is not defined―something that occurs when no class is server-side rendered. E.g., the following HTML

<div wp-class:foo="state.falseValue"></div>
<button wp-on:click="actions.toggleFalseValue">Toggle</button>

currently throws this error:

Screenshot 2023-02-14 at 18 51 25

Also, when the button is clicked, the application crashes.

Why

Directives should take care of those attributes they affect.

In this case, developers shouldn't be forced to write an empty class to make the wp-class directive work as expected.

How

Simply using an empty string when element.props.class is undefined.

@DAreRodz DAreRodz added the bug Something isn't working label Feb 14, 2023
Copy link
Member

@luisherranz luisherranz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@DAreRodz DAreRodz merged commit a199954 into main-wp-directives-plugin Feb 20, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants