Skip to content

Commit b87d57d

Browse files
trueadmRich-Harris
andauthored
fix: add anchor support to mount() API (#11050)
* fix: add `anchor` support to mount() API * use ?? * fix inconsistent formatting * required options before optional ones * regenerate types --------- Co-authored-by: Rich Harris <[email protected]>
1 parent b2892b0 commit b87d57d

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

.changeset/afraid-geckos-dance.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+
fix: add `anchor` support to mount() API

packages/svelte/src/internal/client/render.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,16 @@ export function stringify(value) {
9090
* @param {import('../../index.js').ComponentType<import('../../index.js').SvelteComponent<Props, Events>>} component
9191
* @param {{
9292
* target: Document | Element | ShadowRoot;
93+
* anchor?: Node;
9394
* props?: Props;
9495
* events?: { [Property in keyof Events]: (e: Events[Property]) => any };
95-
* context?: Map<any, any>;
96+
* context?: Map<any, any>;
9697
* intro?: boolean;
9798
* }} options
9899
* @returns {Exports}
99100
*/
100101
export function mount(component, options) {
101-
const anchor = options.target.appendChild(empty());
102+
const anchor = options.anchor ?? options.target.appendChild(empty());
102103
// Don't flush previous effects to ensure order of outer effects stays consistent
103104
return flush_sync(() => _mount(component, { ...options, anchor }), false);
104105
}
@@ -187,7 +188,7 @@ export function hydrate(component, options) {
187188
* anchor: Node;
188189
* props?: Props;
189190
* events?: { [Property in keyof Events]: (e: Events[Property]) => any };
190-
* context?: Map<any, any>;
191+
* context?: Map<any, any>;
191192
* intro?: boolean;
192193
* }} options
193194
* @returns {Exports}

packages/svelte/types/index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ declare module 'svelte' {
300300
* */
301301
export function mount<Props extends Record<string, any>, Exports extends Record<string, any>, Events extends Record<string, any>>(component: ComponentType<SvelteComponent<Props, Events, any>>, options: {
302302
target: Document | Element | ShadowRoot;
303+
anchor?: Node | undefined;
303304
props?: Props | undefined;
304305
events?: { [Property in keyof Events]: (e: Events[Property]) => any; } | undefined;
305306
context?: Map<any, any> | undefined;

0 commit comments

Comments
 (0)