Skip to content

Commit 9802fd4

Browse files
improve
1 parent ba95b56 commit 9802fd4

File tree

4 files changed

+34
-42
lines changed

4 files changed

+34
-42
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ export function server_component(analysis, options) {
199199
b.stmt(b.call('$$render_inner', b.id('$$inner_payload')))
200200
])
201201
),
202-
b.stmt(b.call('$.assign_payload', b.id('$$payload'), b.id('$$inner_payload')))
202+
b.stmt(b.call('$$payload.subsume', b.id('$$inner_payload')))
203203
];
204204
}
205205

packages/svelte/src/internal/server/index.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -513,8 +513,6 @@ export { push, pop } from './context.js';
513513

514514
export { push_element, pop_element, validate_snippet_args } from './dev.js';
515515

516-
export { assign_payload } from './payload.js';
517-
518516
export { snapshot } from '../shared/clone.js';
519517

520518
export { fallback, to_array } from '../shared/utils.js';
@@ -573,28 +571,21 @@ export function valueless_option(payload, children) {
573571

574572
// post-children, `payload` has child content, possibly also with some number of hydration comments.
575573
// we can compact this last chunk of content to see if it matches the select value...
576-
let match = false;
577574
payload.compact({
578575
start: i,
579576
fn: (body) => {
580577
if (body.replace(/<!---->/g, '') === payload.select_value) {
581-
match = true;
578+
// ...and if it does match the select value, we can compact the part of the payload representing the `<option ...>`
579+
// to add the `selected` attribute to the end.
580+
payload.compact({
581+
start: i - 1,
582+
end: i,
583+
fn: (body) => {
584+
return body.slice(0, -1) + ' selected>';
585+
}
586+
});
582587
}
583588
return body;
584589
}
585590
});
586-
587-
if (!match) {
588-
return;
589-
}
590-
591-
// ...and if it does match the select value, we can compact the part of the payload representing the `<option ...>`
592-
// to add the `selected` attribute to the end.
593-
payload.compact({
594-
start: i - 1,
595-
end: i,
596-
fn: (body) => {
597-
return body.slice(0, -1) + ' selected>';
598-
}
599-
});
600591
}

packages/svelte/src/internal/server/payload.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,18 @@ export class HeadPayload extends BasePayload {
194194
head_payload.out = [...this.out];
195195
return head_payload;
196196
}
197+
198+
/**
199+
* @param {HeadPayload} other
200+
*/
201+
subsume(other) {
202+
// @ts-expect-error
203+
this.out = [...other.out];
204+
this.promise = other.promise;
205+
this.#css = other.#css;
206+
this.#title = other.#title;
207+
this.#uid = other.#uid;
208+
}
197209
}
198210

199211
/**
@@ -250,29 +262,18 @@ export class Payload extends BasePayload {
250262
payload.out = [...this.out];
251263
return payload;
252264
}
253-
}
254265

255-
/**
256-
* Assigns second payload to first -- legacy nonsense
257-
* @param {Payload} p1
258-
* @param {Payload} p2
259-
* @returns {void}
260-
*/
261-
export function assign_payload(p1, p2) {
262-
p1.out = [...p2.out];
263-
p1.promise = p2.promise;
264-
p1.css.clear();
265-
for (const entry of p2.css) {
266-
p1.css.add(entry);
267-
}
268-
269-
p1.head.out = [...p2.head.out];
270-
p1.head.promise = p2.head.promise;
271-
p1.head.css.clear();
272-
for (const entry of p2.head.css) {
273-
p1.head.css.add(entry);
266+
/**
267+
* @param {Payload} other
268+
*/
269+
subsume(other) {
270+
// @ts-expect-error
271+
this.out = [...other.out];
272+
this.promise = other.promise;
273+
this.#css = other.#css;
274+
this.#uid = other.#uid;
275+
this.#head.subsume(other.#head);
274276
}
275-
p1.head.title.value = p2.head.title.value;
276277
}
277278

278279
/**

packages/svelte/tests/snapshot/samples/bind-component-snippet/_expected/server/index.svelte.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,10 @@ export default function Bind_component_snippet($$payload) {
3131

3232
do {
3333
$$settled = true;
34-
$$inner_payload = $.copy_payload($$payload);
34+
$$inner_payload = $$payload.copy();
3535
$$render_inner($$inner_payload);
3636
} while (!$$settled);
3737

38-
$.assign_payload($$payload, $$inner_payload);
38+
$$payload.subsume($$inner_payload);
3939
});
4040
}

0 commit comments

Comments
 (0)