Skip to content

Persistent Child Component #10765

Answered by brunnerh
kalkronline asked this question in Q&A
Discussion options

You must be logged in to vote

To my knowledge the only way to have elements move is via...

  • a keyed {#each} block (items can change position)
  • manual DOM manipulation, e.g. via an action

You could render the snippet programmatically and move the contents around, it's quite hacky, though.
Making something like this work with SSR would probably require conditional branching.

Relevant code
<script>
	import { mountSnippet } from './Render.svelte';

	let { children } = $props();
	let border = $state(true);

	let renderedChildren = null;
	function insertDom(node) {
		if (renderedChildren == null) {
			mountSnippet(node, children);
			renderedChildren = [...node.childNodes];
		}

		node.replaceWith(...renderedChildren);
	}
</

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by kalkronline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants