Skip to content

Commit 72b066b

Browse files
feat: allow non-synchronous legacy component instantiation (#12970)
* feat: allow non-synchronous legacy component instantiation Add a new option to the legacy class component interface so that `flush_sync` can be omitted. Part of sveltejs/kit#12248 * lint --------- Co-authored-by: Rich Harris <[email protected]>
1 parent c5c54da commit 72b066b

File tree

5 files changed

+11
-12
lines changed

5 files changed

+11
-12
lines changed

.changeset/wet-pears-buy.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
feat: allow non-synchronous legacy component instantiation

packages/svelte/src/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ export interface ComponentConstructorOptions<
1717
context?: Map<any, any>;
1818
hydrate?: boolean;
1919
intro?: boolean;
20+
recover?: boolean;
21+
sync?: boolean;
2022
$$inline?: boolean;
2123
}
2224

packages/svelte/src/legacy/legacy-client.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@ import { define_property } from '../internal/shared/utils.js';
1717
*
1818
* @param {ComponentConstructorOptions<Props> & {
1919
* component: ComponentType<SvelteComponent<Props, Events, Slots>> | Component<Props>;
20-
* immutable?: boolean;
21-
* hydrate?: boolean;
22-
* recover?: boolean;
2320
* }} options
2421
* @returns {SvelteComponent<Props, Events, Slots> & Exports}
2522
*/
@@ -64,9 +61,6 @@ class Svelte4Component {
6461
/**
6562
* @param {ComponentConstructorOptions & {
6663
* component: any;
67-
* immutable?: boolean;
68-
* hydrate?: boolean;
69-
* recover?: false;
7064
* }} options
7165
*/
7266
constructor(options) {
@@ -110,8 +104,8 @@ class Svelte4Component {
110104
recover: options.recover
111105
});
112106

113-
// We don't flush_sync for custom element wrappers
114-
if (!options?.props?.$$host) {
107+
// We don't flush_sync for custom element wrappers or if the user doesn't want it
108+
if (!options?.props?.$$host || options.sync === false) {
115109
flush_sync();
116110
}
117111

packages/svelte/tests/runtime-legacy/shared.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,6 @@ async function run_test_variant(
351351
component: mod.default,
352352
props: config.props,
353353
target,
354-
immutable: config.immutable,
355354
intro: config.intro,
356355
recover: config.recover ?? false,
357356
hydrate: variant === 'hydrate'

packages/svelte/types/index.d.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ declare module 'svelte' {
1414
context?: Map<any, any>;
1515
hydrate?: boolean;
1616
intro?: boolean;
17+
recover?: boolean;
18+
sync?: boolean;
1719
$$inline?: boolean;
1820
}
1921

@@ -2101,9 +2103,6 @@ declare module 'svelte/legacy' {
21012103
* */
21022104
export function createClassComponent<Props extends Record<string, any>, Exports extends Record<string, any>, Events extends Record<string, any>, Slots extends Record<string, any>>(options: ComponentConstructorOptions<Props> & {
21032105
component: ComponentType<SvelteComponent<Props, Events, Slots>> | Component<Props>;
2104-
immutable?: boolean;
2105-
hydrate?: boolean;
2106-
recover?: boolean;
21072106
}): SvelteComponent<Props, Events, Slots> & Exports;
21082107
/**
21092108
* Takes the component function and returns a Svelte 4 compatible component constructor.

0 commit comments

Comments
 (0)