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

Fixed value change observers not firing #697

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

RBastianini
Copy link

Fixed value change observers not firing when the controller name
contains upper case characters.

Fixes #680.

Fixed value change observers not firing when the controller name
contains upper case characters.
@RBastianini
Copy link
Author

I haven't found documentation about this, but it looks like the mutation observer reports property names always in lowercase (and since HTML is supposed to be case insensitive, I think it's fair). For this reason, my fix is to also track the properties that stimulus cares about in lowercase. I'm not sure the spot I touched is the right one, but at least no other test breaks.

@@ -43,6 +43,6 @@ export class DataMap {
}

getAttributeNameForKey(key: string): string {
return `data-${this.identifier}-${dasherize(key)}`
return `data-${this.identifier.toLowerCase()}-${dasherize(key)}`
Copy link
Member

Choose a reason for hiding this comment

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

I'm not sure if this is the right fix for the issue raised in #680. The attribute methods on Element seem to be case-insensitive, which leads me to believe that we need to week this somewhere else.

Copy link
Author

Choose a reason for hiding this comment

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

If I get what you mean, they are case insensitive, meaning that you can read or write them with whatever casing and it would still work, but the mutation observer always reports the changed properties as lowercase strings. The consequence is that when we check if we should care about the property change, we always opt to discard the change event, because we instead stored the property with whatever casing was found in the document. I've not found this documented anywhere, but I tried both Chromium and Firefox and both did the same.

If I didn't get what you mean, could you point me in the direction where you think the fix should be made instead?

Copy link
Member

Choose a reason for hiding this comment

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

Hey @RBastianini, I just realized that my comment wasn't very well thought out, sorry about that! Let me dig into this and come back with a more constructive answer. Thank you!

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

Successfully merging this pull request may close these issues.

Change obeserver not called if controller name contains uppercase characters
2 participants