Skip to content

DOM Processing Fails Due to apply() Being Called Before Custom Plugins Are Loaded #740

@mat02

Description

@mat02

Datastar fails to process the DOM if an HTML document contains references to a custom plugin before it is loaded via the load() function.

This issue arises in beta9, where in the bundled version, apply() is called immediately after load():
https://github.com/starfederation/datastar/blob/main/library/src/bundles/datastar.ts#L66.
As a result, DOM processing starts before the plugin is loaded, causing errors on full page load.

However, when a new fragment is sent via SSE, the custom plugin is correctly recognized and applied.

import { apply, load } from 'datastar'  // HTML is being processed immediately and fails if it references an action from the custom plugin
load(
   MyCustomPlugin
    // Plugin is loaded here, but it's too late for initial processing
)
apply()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions