Skip to content

Support slots in IIFE (non-deferred) in light DOM #7

Closed
@patricknelson

Description

@patricknelson

Describe the problem

Currently slots are not properly rendered when the the entrypoint defining the custom elements and associated Svelte components run prior to the initial parsing of the DOM. As the parser processes HTML, it will encounter the custom element and immediately as soon as it is encountered, it will execute the constructor() and connectedCallback() functions even before it has reached the interior containing the slots.

Describe the proposed solution

Use MutationObserver to watch for changes and re-render the component once slots are encountered. This is how shadow DOM slots are already being addressed.

Alternatives considered

Await tick() (e.g. setTimeout() with 0ms delay) to wait until thread is no longer blocking, but this is super hacky and also causes a flicker. The requestAnimationFrame() would be similarly as hacky if not induce a longer delay.

Note: Very important to me since our components are compiled as IIFE's (see rollup docs) and included early in the page load (i.e. in the <head>) and thus this currently renders slots unusable.

Importance

i cannot use svelte-retag without it

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions