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()