[LiveComponent] Return empty string for data-value=""
instead of falling back to null
#3031
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
Demo video
before.mov
When using
data-value=""
on an element, the current implementation incorrectly returnsnull
instead of the intended empty string value. This happens because the conditionif (element.dataset.value)
evaluates tofalse
for empty strings (since empty strings are falsy in JavaScript), causing the function to fall through to the finalreturn null;
statement.Impact
This behavior prevents developers from explicitly setting empty string values via the
data-value
attribute, which is a common use case for clearing form fields or resetting values to empty states rather thannull
.Current behavior:
Expected behavior:
After (demo video)
after.mov
Changes
Replace the truthiness check
if (element.dataset.value)
with an explicit attribute existence checkif (element.hasAttribute("data-value"))
. This ensures that anydata-value
attribute, including those with empty string values, are properly processed and returned.Manual testing done
data-value=""
now returns""
data-value="test"
still returns"test"
data-value
attribute still falls back to other value sources