Skip to content

Commit bfd9570

Browse files
committed
get rid of spread_dynamic_element_attributes_effect
1 parent 0f56430 commit bfd9570

File tree

2 files changed

+30
-48
lines changed

2 files changed

+30
-48
lines changed

packages/svelte/src/compiler/phases/3-transform/client/visitors/template.js

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,8 @@ function serialize_dynamic_element_attributes(attributes, context, element_id) {
343343
return false;
344344
}
345345

346+
// TODO why are we always treating this as a spread? needs docs, if that's not an error
347+
346348
let needs_isolation = false;
347349
let is_reactive = false;
348350

@@ -365,51 +367,45 @@ function serialize_dynamic_element_attributes(attributes, context, element_id) {
365367
attribute.type === 'SpreadAttribute' && attribute.metadata.contains_call_expression;
366368
}
367369

368-
const isolated = b.stmt(
369-
b.call(
370-
'$.spread_dynamic_element_attributes_effect',
371-
element_id,
372-
b.thunk(b.array(values)),
373-
b.literal(context.state.analysis.css.hash)
374-
)
375-
);
376-
377-
if (needs_isolation) {
378-
context.state.init.push(isolated);
379-
return false;
380-
} else if (is_reactive) {
370+
if (needs_isolation || is_reactive) {
381371
const id = context.state.scope.generate('spread_attributes');
382372
context.state.init.push(b.let(id));
383-
context.state.update.push(
384-
b.stmt(
385-
b.assignment(
386-
'=',
387-
b.id(id),
388-
b.call(
389-
'$.spread_dynamic_element_attributes',
390-
element_id,
391-
b.id(id),
392-
b.array(values),
393-
b.literal(context.state.analysis.css.hash)
394-
)
395-
)
396-
)
397-
);
398-
return true;
399-
} else {
400-
context.state.init.push(
401-
b.stmt(
373+
374+
const update = b.stmt(
375+
b.assignment(
376+
'=',
377+
b.id(id),
402378
b.call(
403379
'$.spread_dynamic_element_attributes',
404380
element_id,
405-
b.literal(null),
381+
b.id(id),
406382
b.array(values),
407383
b.literal(context.state.analysis.css.hash)
408384
)
409385
)
410386
);
411-
return false;
387+
388+
if (needs_isolation) {
389+
context.state.init.push(serialize_update(update));
390+
return false;
391+
}
392+
393+
context.state.update.push(update);
394+
return true;
412395
}
396+
397+
context.state.init.push(
398+
b.stmt(
399+
b.call(
400+
'$.spread_dynamic_element_attributes',
401+
element_id,
402+
b.literal(null),
403+
b.array(values),
404+
b.literal(context.state.analysis.css.hash)
405+
)
406+
)
407+
);
408+
return false;
413409
}
414410

415411
/**

packages/svelte/src/internal/client/dom/elements/attributes.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -184,20 +184,6 @@ export function spread_attributes(element, prev, attrs, lowercase_attributes, cs
184184
return next;
185185
}
186186

187-
/**
188-
* @param {Element} node
189-
* @param {() => Record<string, unknown>[]} attrs
190-
* @param {string} css_hash
191-
*/
192-
export function spread_dynamic_element_attributes_effect(node, attrs, css_hash) {
193-
/** @type {Record<string, any> | undefined} */
194-
var current;
195-
196-
render_effect(() => {
197-
current = spread_dynamic_element_attributes(node, current, attrs(), css_hash);
198-
});
199-
}
200-
201187
/**
202188
* @param {Element} node
203189
* @param {Record<string, unknown> | undefined} prev

0 commit comments

Comments
 (0)