Skip to content

fix(runtime): unwrap surrogates before writing DOM properties - #260

Open
SixSeven-Labs wants to merge 1 commit into
tokio-rs:mainfrom
SixSeven-Labs:fix-bind-property-unwrap
Open

fix(runtime): unwrap surrogates before writing DOM properties#260
SixSeven-Labs wants to merge 1 commit into
tokio-rs:mainfrom
SixSeven-Labs:fix-bind-property-unwrap

Conversation

@SixSeven-Labs

Copy link
Copy Markdown

ran into this building a little catalog browser on 0.5.0. two checkboxes bound with :checked to false signals, both came up checked.

binding.ts writes value/checked/selected/indeterminate as properties instead of attributes, which is right, but it hands the computed value straight over:

(el as Element & Record<string, unknown>)[name] = value;

that value is a surrogate. objects are truthy, so el.checked = Bool(false) checks the box. and the attribute path right below it does the correct thing and calls removeAttribute, so devtools shows no checked attribute while the property disagrees. took me a minute to find.

value gets away with it by accident. assigning an object goes through toString, and Str.toString hands back the string we wanted anyway.

fix moves the unwrap into propertyValue(name, value). boolean props read isAttributePresent(), value reads toAttributeValue(), or "" when the value is absent since None.toAttributeValue() throws. non surrogate values pass through, coerced to bool for the boolean props so raw! keeps working.

checked against examples/runtime with a few extra inputs on the show page, where off is :checked=$(show.get()) and show starts false:

before: {off: true,  on: true, text: "hidden"}
after:  {off: false, on: true, text: "hidden"}

test is a unit test on propertyValue, no dom needed. dist rebuilt with npm run build.

value, checked, selected and indeterminate are written as properties
rather than attributes, but the computed value went over as-is. A
surrogate is an object and every object is truthy, so Bool(false) landed
on checked as a truthy object and the box rendered checked whatever the
expression said.

value got away with it: assigning an object stringifies through toString,
which for Str happens to be the text we wanted anyway.
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.

1 participant