File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed
compiler/phases/3-transform/client/visitors
internal/client/dom/elements Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -172,7 +172,16 @@ export function RegularElement(node, context) {
172172 bindings . has ( 'group' ) ||
173173 ( ! bindings . has ( 'group' ) && has_value_attribute ) )
174174 ) {
175- context . state . init . push ( b . stmt ( b . call ( '$.remove_input_defaults' , context . state . node ) ) ) ;
175+ const spreads = has_spread
176+ ? b . object (
177+ attributes
178+ . filter ( ( attr ) => attr . type === 'SpreadAttribute' )
179+ . map ( ( attr ) => b . spread ( attr . expression ) )
180+ )
181+ : null ;
182+ context . state . init . push (
183+ b . stmt ( b . call ( '$.remove_input_defaults' , context . state . node , spreads ) )
184+ ) ;
176185 }
177186 }
178187
Original file line number Diff line number Diff line change @@ -31,14 +31,20 @@ const IS_CUSTOM_ELEMENT = Symbol('is custom element');
3131const IS_HTML = Symbol ( 'is html' ) ;
3232
3333/**
34- * The value/checked attribute in the template actually corresponds to the defaultValue property, so we need
35- * to remove it upon hydration to avoid a bug when someone resets the form value.
34+ * The value/checked attribute in the template actually corresponds to the defaultValue property,
35+ * so we need to remove it upon hydration to avoid a bug when someone resets the form value,
36+ * unless the property is presented in the spreaded objects and is handled by `set_attributes()`
3637 * @param {HTMLInputElement } input
38+ * @param {Record<string, any> } [spread]
3739 * @returns {void }
3840 */
39- export function remove_input_defaults ( input ) {
41+ export function remove_input_defaults ( input , spread ) {
4042 if ( ! hydrating ) return ;
4143
44+ if ( spread && ( input . type === 'checkbox' ? 'defaultChecked' : 'defaultValue' ) in spread ) {
45+ return ;
46+ }
47+
4248 var already_removed = false ;
4349
4450 // We try and remove the default attributes later, rather than sync during hydration.
You can’t perform that action at this time.
0 commit comments