Skip to content

Commit 20edfe1

Browse files
authored
Merge branch 'main' into defer-effects-in-pending-boundary
2 parents f41dad7 + 72ce753 commit 20edfe1

File tree

51 files changed

+532
-290
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+532
-290
lines changed

packages/svelte/CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# svelte
22

3+
## 5.38.9
4+
5+
### Patch Changes
6+
7+
- chore: generate CSS hash using the filename ([#16740](https://github.com/sveltejs/svelte/pull/16740))
8+
9+
- fix: correctly analyze `<object.property>` components ([#16711](https://github.com/sveltejs/svelte/pull/16711))
10+
11+
- fix: clean up scheduling system ([#16741](https://github.com/sveltejs/svelte/pull/16741))
12+
13+
- fix: transform input defaults from spread ([#16481](https://github.com/sveltejs/svelte/pull/16481))
14+
15+
- fix: don't destroy contents of `svelte:boundary` unless the boundary is an error boundary ([#16746](https://github.com/sveltejs/svelte/pull/16746))
16+
317
## 5.38.8
418

519
### Patch Changes

packages/svelte/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "svelte",
33
"description": "Cybernetically enhanced web apps",
44
"license": "MIT",
5-
"version": "5.38.8",
5+
"version": "5.38.9",
66
"type": "module",
77
"types": "./types/index.d.ts",
88
"engines": {

packages/svelte/src/compiler/phases/2-analyze/index.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -456,10 +456,19 @@ export function analyze_component(root, source, options) {
456456

457457
const is_custom_element = !!options.customElementOptions || options.customElement;
458458

459+
const name = module.scope.generate(options.name ?? component_name);
460+
461+
state.adjust({
462+
component_name: name,
463+
dev: options.dev,
464+
rootDir: options.rootDir,
465+
runes
466+
});
467+
459468
// TODO remove all the ?? stuff, we don't need it now that we're validating the config
460469
/** @type {ComponentAnalysis} */
461470
const analysis = {
462-
name: module.scope.generate(options.name ?? component_name),
471+
name,
463472
root: scope_root,
464473
module,
465474
instance,
@@ -520,7 +529,7 @@ export function analyze_component(root, source, options) {
520529
hash: root.css
521530
? options.cssHash({
522531
css: root.css.content.styles,
523-
filename: options.filename,
532+
filename: state.filename,
524533
name: component_name,
525534
hash
526535
})
@@ -534,13 +543,6 @@ export function analyze_component(root, source, options) {
534543
async_deriveds: new Set()
535544
};
536545

537-
state.adjust({
538-
component_name: analysis.name,
539-
dev: options.dev,
540-
rootDir: options.rootDir,
541-
runes
542-
});
543-
544546
if (!runes) {
545547
// every exported `let` or `var` declaration becomes a prop, everything else becomes an export
546548
for (const node of instance.ast.body) {

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ export function RegularElement(node, context) {
7272

7373
let has_spread = node.metadata.has_spread;
7474
let has_use = false;
75+
let should_remove_defaults = false;
7576

7677
for (const attribute of node.attributes) {
7778
switch (attribute.type) {
@@ -172,7 +173,12 @@ export function RegularElement(node, context) {
172173
bindings.has('group') ||
173174
(!bindings.has('group') && has_value_attribute))
174175
) {
175-
context.state.init.push(b.stmt(b.call('$.remove_input_defaults', context.state.node)));
176+
if (has_spread) {
177+
// remove_input_defaults will be called inside set_attributes
178+
should_remove_defaults = true;
179+
} else {
180+
context.state.init.push(b.stmt(b.call('$.remove_input_defaults', context.state.node)));
181+
}
176182
}
177183
}
178184

@@ -202,7 +208,15 @@ export function RegularElement(node, context) {
202208
bindings.has('checked');
203209

204210
if (has_spread) {
205-
build_attribute_effect(attributes, class_directives, style_directives, context, node, node_id);
211+
build_attribute_effect(
212+
attributes,
213+
class_directives,
214+
style_directives,
215+
context,
216+
node,
217+
node_id,
218+
should_remove_defaults
219+
);
206220
} else {
207221
for (const attribute of /** @type {AST.Attribute[]} */ (attributes)) {
208222
if (is_event_attribute(attribute)) {

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,16 @@ import { build_expression, build_template_chunk, Memoizer } from './utils.js';
1616
* @param {ComponentContext} context
1717
* @param {AST.RegularElement | AST.SvelteElement} element
1818
* @param {Identifier} element_id
19+
* @param {boolean} [should_remove_defaults]
1920
*/
2021
export function build_attribute_effect(
2122
attributes,
2223
class_directives,
2324
style_directives,
2425
context,
2526
element,
26-
element_id
27+
element_id,
28+
should_remove_defaults = false
2729
) {
2830
/** @type {ObjectExpression['properties']} */
2931
const values = [];
@@ -91,6 +93,7 @@ export function build_attribute_effect(
9193
element.metadata.scoped &&
9294
context.state.analysis.css.hash !== '' &&
9395
b.literal(context.state.analysis.css.hash),
96+
should_remove_defaults && b.true,
9497
is_ignored(element, 'hydration_attribute_changed') && b.true
9598
)
9699
)

packages/svelte/src/compiler/phases/3-transform/server/visitors/shared/element.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
import { regex_starts_with_newline } from '../../../../patterns.js';
1212
import * as b from '#compiler/builders';
1313
import {
14+
ELEMENT_IS_INPUT,
1415
ELEMENT_IS_NAMESPACED,
1516
ELEMENT_PRESERVE_ATTRIBUTE_CASE
1617
} from '../../../../../../constants.js';
@@ -401,6 +402,8 @@ function build_element_spread_attributes(
401402
flags |= ELEMENT_IS_NAMESPACED | ELEMENT_PRESERVE_ATTRIBUTE_CASE;
402403
} else if (is_custom_element_node(element)) {
403404
flags |= ELEMENT_PRESERVE_ATTRIBUTE_CASE;
405+
} else if (element.type === 'RegularElement' && element.name === 'input') {
406+
flags |= ELEMENT_IS_INPUT;
404407
}
405408

406409
const object = build_spread_object(element, attributes, context);

packages/svelte/src/compiler/phases/scope.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1032,7 +1032,7 @@ export function create_scopes(ast, root, allow_reactive_declarations, parent) {
10321032
},
10331033

10341034
Component: (node, context) => {
1035-
context.state.scope.reference(b.id(node.name), context.path);
1035+
context.state.scope.reference(b.id(node.name.split('.')[0]), context.path);
10361036
Component(node, context);
10371037
},
10381038
SvelteSelf: Component,

packages/svelte/src/compiler/types/index.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ export interface CompileOptions extends ModuleCompileOptions {
105105
css?: 'injected' | 'external';
106106
/**
107107
* A function that takes a `{ hash, css, name, filename }` argument and returns the string that is used as a classname for scoped CSS.
108-
* It defaults to returning `svelte-${hash(css)}`.
108+
* It defaults to returning `svelte-${hash(filename ?? css)}`.
109109
*
110110
* @default undefined
111111
*/

packages/svelte/src/compiler/validate-options.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ const component_options = {
7070
return input;
7171
}),
7272

73-
cssHash: fun(({ css, hash }) => {
74-
return `svelte-${hash(css)}`;
73+
cssHash: fun(({ css, filename, hash }) => {
74+
return `svelte-${hash(filename === '(unknown)' ? css : filename ?? css)}`;
7575
}),
7676

7777
// TODO this is a sourcemap option, would be good to put under a sourcemap namespace

packages/svelte/src/constants.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export const HYDRATION_ERROR = {};
2828

2929
export const ELEMENT_IS_NAMESPACED = 1;
3030
export const ELEMENT_PRESERVE_ATTRIBUTE_CASE = 1 << 1;
31+
export const ELEMENT_IS_INPUT = 1 << 2;
3132

3233
export const UNINITIALIZED = Symbol();
3334

0 commit comments

Comments
 (0)