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

Don't stringify properties with undefined values in flushToDOM #5549

Merged
merged 1 commit into from
Jun 27, 2024

Conversation

mrxz
Copy link
Contributor

@mrxz mrxz commented Jun 27, 2024

Description:
This PR ensures that the stringification process skips over properties with undefined values. These would otherwise lead to the string literal "undefined" ending up in the output.

Context for this change: aframevr/aframe-inspector#722 (comment)
Prior to 1.6.0 an empty string would remain an empty string, but now ends up as undefined, hence causing issue when using flushToDOM. The reason to change the stringification behaviour is that even in version <=1.5.0 it's possible to end up with undefined values (e.g. removeAttribute('material', 'src')).

Take for example the following operations:

el.setAttribute('test', {a: 'Value', b: 'Another value'});
el.setAttribute('test', 'a', '');
el.removeAttribute('test', 'b');
el.flushToDOM();

Would lead to the following outputs:

Version Internal attrValue Output
1.5.0 {a: '', b: undefined} "a: ; b: undefined"
1.6.0 / master {a: undefined, b: undefined} "a: undefined; b: undefined"
this PR {a: undefined, b: undefined} ""

Changes proposed:

  • Skip over properties with undefined values when stringifying
  • Add unit test covering this behaviour when using flushToDOM

@dmarcos
Copy link
Member

dmarcos commented Jun 27, 2024

Thanks!

@dmarcos dmarcos merged commit 230d4f7 into aframevr:master Jun 27, 2024
1 check passed
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

Successfully merging this pull request may close these issues.

2 participants