svelte 5.49.0 → 5.49.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "svelte",
3
3
  "description": "Cybernetically enhanced web apps",
4
4
  "license": "MIT",
5
- "version": "5.49.0",
5
+ "version": "5.49.1",
6
6
  "type": "module",
7
7
  "types": "./types/index.d.ts",
8
8
  "engines": {
@@ -139,7 +139,7 @@
139
139
  ],
140
140
  "devDependencies": {
141
141
  "@jridgewell/trace-mapping": "^0.3.25",
142
- "@playwright/test": "^1.46.1",
142
+ "@playwright/test": "^1.58.0",
143
143
  "@rollup/plugin-commonjs": "^28.0.1",
144
144
  "@rollup/plugin-node-resolve": "^15.3.0",
145
145
  "@rollup/plugin-terser": "^0.4.4",
@@ -165,7 +165,7 @@
165
165
  "clsx": "^2.1.1",
166
166
  "devalue": "^5.6.2",
167
167
  "esm-env": "^1.2.1",
168
- "esrap": "^2.2.1",
168
+ "esrap": "^2.2.2",
169
169
  "is-reference": "^3.0.3",
170
170
  "locate-character": "^3.0.0",
171
171
  "magic-string": "^0.30.11",
@@ -70,8 +70,7 @@ export function RegularElement(node, context) {
70
70
  if (optimiser.expressions.length > 0) {
71
71
  context.state.template.push(
72
72
  create_child_block(
73
- b.block([optimiser.apply(), ...state.init, ...build_template(state.template)]),
74
- true
73
+ b.block([optimiser.apply(), ...state.init, ...build_template(state.template)])
75
74
  )
76
75
  );
77
76
  } else {
@@ -133,7 +132,7 @@ export function RegularElement(node, context) {
133
132
 
134
133
  if (optimiser.expressions.length > 0) {
135
134
  context.state.template.push(
136
- create_child_block(b.block([optimiser.apply(), ...state.init, statement]), true)
135
+ create_child_block(b.block([optimiser.apply(), ...state.init, statement]))
137
136
  );
138
137
  } else {
139
138
  context.state.template.push(...state.init, statement);
@@ -186,7 +185,7 @@ export function RegularElement(node, context) {
186
185
 
187
186
  if (optimiser.expressions.length > 0) {
188
187
  context.state.template.push(
189
- create_child_block(b.block([optimiser.apply(), ...state.init, statement]), true)
188
+ create_child_block(b.block([optimiser.apply(), ...state.init, statement]))
190
189
  );
191
190
  } else {
192
191
  context.state.template.push(...state.init, statement);
@@ -236,18 +235,19 @@ export function RegularElement(node, context) {
236
235
  }
237
236
 
238
237
  if (optimiser.is_async()) {
239
- let statement = create_child_block(
240
- b.block([optimiser.apply(), ...state.init, ...build_template(state.template)]),
241
- true
242
- );
238
+ let statements = [...state.init, ...build_template(state.template)];
239
+
240
+ if (optimiser.has_await) {
241
+ statements = [create_child_block(b.block([optimiser.apply(), ...statements]))];
242
+ }
243
243
 
244
244
  const blockers = optimiser.blockers();
245
245
 
246
246
  if (blockers.elements.length > 0) {
247
- statement = create_async_block(b.block([statement]), blockers, false, false);
247
+ statements = [create_async_block(b.block(statements), blockers, false, false)];
248
248
  }
249
249
 
250
- context.state.template.push(statement);
250
+ context.state.template.push(...statements);
251
251
  } else {
252
252
  context.state.init.push(...state.init);
253
253
  context.state.template.push(...state.template);
@@ -79,7 +79,7 @@ export function SvelteElement(node, context) {
79
79
  );
80
80
 
81
81
  if (optimiser.expressions.length > 0) {
82
- statement = create_child_block(b.block([optimiser.apply(), statement]), true);
82
+ statement = create_child_block(b.block([optimiser.apply(), statement]));
83
83
  }
84
84
 
85
85
  statements.push(statement);
@@ -264,11 +264,10 @@ export function build_getter(node, state) {
264
264
  /**
265
265
  * Creates a `$$renderer.child(...)` expression statement
266
266
  * @param {BlockStatement | Expression} body
267
- * @param {boolean} async
268
267
  * @returns {Statement}
269
268
  */
270
- export function create_child_block(body, async) {
271
- return b.stmt(b.call('$$renderer.child', b.arrow([b.id('$$renderer')], body, async)));
269
+ export function create_child_block(body) {
270
+ return b.stmt(b.call('$$renderer.child', b.arrow([b.id('$$renderer')], body, true)));
272
271
  }
273
272
 
274
273
  /**
@@ -115,57 +115,17 @@ function base_element(node, context) {
115
115
  const is_doctype_node = node.name.toLowerCase() === '!doctype';
116
116
  const is_self_closing =
117
117
  is_void(node.name) || (node.type === 'Component' && node.fragment.nodes.length === 0);
118
- let multiline_content = false;
119
118
 
120
119
  if (is_doctype_node) child_context.write(`>`);
121
120
  else if (is_self_closing) {
122
121
  child_context.write(`${multiline_attributes ? '' : ' '}/>`);
123
122
  } else {
124
123
  child_context.write('>');
125
-
126
- // Process the element's content in a separate context for measurement
127
- const content_context = child_context.new();
128
- const allow_inline_content = child_context.measure() < LINE_BREAK_THRESHOLD;
129
- block(content_context, node.fragment, allow_inline_content);
130
-
131
- // Determine if content should be formatted on multiple lines
132
- multiline_content = content_context.measure() > LINE_BREAK_THRESHOLD;
133
-
134
- if (multiline_content) {
135
- child_context.newline();
136
-
137
- // Only indent if attributes are inline and content itself isn't already multiline
138
- const should_indent = !multiline_attributes && !content_context.multiline;
139
- if (should_indent) {
140
- child_context.indent();
141
- }
142
-
143
- child_context.append(content_context);
144
-
145
- if (should_indent) {
146
- child_context.dedent();
147
- }
148
-
149
- child_context.newline();
150
- } else {
151
- child_context.append(content_context);
152
- }
153
-
124
+ block(child_context, node.fragment, true);
154
125
  child_context.write(`</${node.name}>`);
155
126
  }
156
127
 
157
- const break_line_after = child_context.measure() > LINE_BREAK_THRESHOLD;
158
-
159
- if ((multiline_content || multiline_attributes) && !context.empty()) {
160
- context.newline();
161
- }
162
-
163
128
  context.append(child_context);
164
-
165
- if (is_self_closing) return;
166
- if (multiline_content || multiline_attributes || break_line_after) {
167
- context.newline();
168
- }
169
129
  }
170
130
 
171
131
  /** @type {Visitors<AST.SvelteNode>} */
@@ -412,6 +372,8 @@ const svelte_visitors = {
412
372
  }
413
373
  } else {
414
374
  sequence.push(child_node);
375
+
376
+ if (child_node.type === 'RegularElement') flush();
415
377
  }
416
378
  }
417
379
 
@@ -420,18 +382,20 @@ const svelte_visitors = {
420
382
  let multiline = false;
421
383
  let width = 0;
422
384
 
423
- const child_contexts = items.map((sequence) => {
424
- const child_context = context.new();
385
+ const child_contexts = items
386
+ .filter((x) => x.length > 0)
387
+ .map((sequence) => {
388
+ const child_context = context.new();
425
389
 
426
- for (const node of sequence) {
427
- child_context.visit(node);
428
- multiline ||= child_context.multiline;
429
- }
390
+ for (const node of sequence) {
391
+ child_context.visit(node);
392
+ multiline ||= child_context.multiline;
393
+ }
430
394
 
431
- width += child_context.measure();
395
+ width += child_context.measure();
432
396
 
433
- return child_context;
434
- });
397
+ return child_context;
398
+ });
435
399
 
436
400
  multiline ||= width > LINE_BREAK_THRESHOLD;
437
401
 
@@ -122,6 +122,10 @@ export function child(node, is_text) {
122
122
  return text;
123
123
  }
124
124
 
125
+ if (is_text) {
126
+ merge_text_nodes(/** @type {Text} */ (child));
127
+ }
128
+
125
129
  set_hydrate_node(child);
126
130
  return child;
127
131
  }
@@ -142,14 +146,18 @@ export function first_child(node, is_text = false) {
142
146
  return first;
143
147
  }
144
148
 
145
- // if an {expression} is empty during SSR, there might be no
146
- // text node to hydrate we must therefore create one
147
- if (is_text && hydrate_node?.nodeType !== TEXT_NODE) {
148
- var text = create_text();
149
+ if (is_text) {
150
+ // if an {expression} is empty during SSR, there might be no
151
+ // text node to hydrate we must therefore create one
152
+ if (hydrate_node?.nodeType !== TEXT_NODE) {
153
+ var text = create_text();
149
154
 
150
- hydrate_node?.before(text);
151
- set_hydrate_node(text);
152
- return text;
155
+ hydrate_node?.before(text);
156
+ set_hydrate_node(text);
157
+ return text;
158
+ }
159
+
160
+ merge_text_nodes(/** @type {Text} */ (hydrate_node));
153
161
  }
154
162
 
155
163
  return hydrate_node;
@@ -175,20 +183,24 @@ export function sibling(node, count = 1, is_text = false) {
175
183
  return next_sibling;
176
184
  }
177
185
 
178
- // if a sibling {expression} is empty during SSR, there might be no
179
- // text node to hydrate we must therefore create one
180
- if (is_text && next_sibling?.nodeType !== TEXT_NODE) {
181
- var text = create_text();
182
- // If the next sibling is `null` and we're handling text then it's because
183
- // the SSR content was empty for the text, so we need to generate a new text
184
- // node and insert it after the last sibling
185
- if (next_sibling === null) {
186
- last_sibling?.after(text);
187
- } else {
188
- next_sibling.before(text);
186
+ if (is_text) {
187
+ // if a sibling {expression} is empty during SSR, there might be no
188
+ // text node to hydrate we must therefore create one
189
+ if (next_sibling?.nodeType !== TEXT_NODE) {
190
+ var text = create_text();
191
+ // If the next sibling is `null` and we're handling text then it's because
192
+ // the SSR content was empty for the text, so we need to generate a new text
193
+ // node and insert it after the last sibling
194
+ if (next_sibling === null) {
195
+ last_sibling?.after(text);
196
+ } else {
197
+ next_sibling.before(text);
198
+ }
199
+ set_hydrate_node(text);
200
+ return text;
189
201
  }
190
- set_hydrate_node(text);
191
- return text;
202
+
203
+ merge_text_nodes(/** @type {Text} */ (next_sibling));
192
204
  }
193
205
 
194
206
  set_hydrate_node(next_sibling);
@@ -258,3 +270,24 @@ export function set_attribute(element, key, value = '') {
258
270
  }
259
271
  return element.setAttribute(key, value);
260
272
  }
273
+
274
+ /**
275
+ * Browsers split text nodes larger than 65536 bytes when parsing.
276
+ * For hydration to succeed, we need to stitch them back together
277
+ * @param {Text} text
278
+ */
279
+ export function merge_text_nodes(text) {
280
+ if (/** @type {string} */ (text.nodeValue).length < 65536) {
281
+ return;
282
+ }
283
+
284
+ let next = text.nextSibling;
285
+
286
+ while (next !== null && next.nodeType === TEXT_NODE) {
287
+ next.remove();
288
+
289
+ /** @type {string} */ (text.nodeValue) += /** @type {string} */ (next.nodeValue);
290
+
291
+ next = text.nextSibling;
292
+ }
293
+ }
@@ -4,11 +4,13 @@ import { hydrate_next, hydrate_node, hydrating, set_hydrate_node } from './hydra
4
4
  import {
5
5
  create_text,
6
6
  get_first_child,
7
+ get_next_sibling,
7
8
  is_firefox,
8
9
  create_element,
9
10
  create_fragment,
10
11
  create_comment,
11
- set_attribute
12
+ set_attribute,
13
+ merge_text_nodes
12
14
  } from './operations.js';
13
15
  import { create_fragment_from_html } from './reconciler.js';
14
16
  import { active_effect } from '../runtime.js';
@@ -310,6 +312,8 @@ export function text(value = '') {
310
312
  // if an {expression} is empty during SSR, we need to insert an empty text node
311
313
  node.before((node = create_text()));
312
314
  set_hydrate_node(node);
315
+ } else {
316
+ merge_text_nodes(/** @type {Text} */ (node));
313
317
  }
314
318
 
315
319
  assign_nodes(node, node);
@@ -11,6 +11,7 @@ import { attributes } from './index.js';
11
11
  import { get_render_context, with_render_context, init_render_context } from './render-context.js';
12
12
  import { sha256 } from './crypto.js';
13
13
  import * as devalue from 'devalue';
14
+ import { noop } from '../shared/utils.js';
14
15
 
15
16
  /** @typedef {'head' | 'body'} RendererType */
16
17
  /** @typedef {{ [key in RendererType]: string }} AccumulatedContent */
@@ -162,6 +163,11 @@ export class Renderer {
162
163
  promises.push(promise);
163
164
  }
164
165
 
166
+ // prevent unhandled rejections, and attach the promise to the renderer instance
167
+ // so that rejections correctly cause rendering to fail
168
+ promise.catch(noop);
169
+ this.promise = promise;
170
+
165
171
  return promises;
166
172
  }
167
173
 
package/src/version.js CHANGED
@@ -4,5 +4,5 @@
4
4
  * The current version, as set in package.json.
5
5
  * @type {string}
6
6
  */
7
- export const VERSION = '5.49.0';
7
+ export const VERSION = '5.49.1';
8
8
  export const PUBLIC_VERSION = '5';