Skip to content

Add a deferred tree initialization primitive - #4886

Closed
calebporzio wants to merge 3 commits into
mainfrom
codex/deferred-init
Closed

calebporzio wants to merge 3 commits into
mainfrom
codex/deferred-init

Conversation

@calebporzio

Copy link
Copy Markdown
Collaborator

Problem

  • What users experience: Framework extensions that load component-scoped JavaScript asynchronously can lose a race with Alpine. Alpine initializes the component tree first, so directives fail because the data, magics, or actions supplied by that JavaScript do not exist yet.
  • What users expected: A component tree should initialize only after its declared prerequisite is ready, while unrelated Alpine trees continue normally.
  • Why reality differs: Alpine initialization is synchronous and currently has no supported per-tree suspension point. Integrations therefore have to manipulate private ignore/marker state and manually re-run initialization, which can double-initialize directives or miss DOM lifecycle cases.

Solution

The public contract stays deliberately small: an init interceptor synchronously registers one or more promises for an element. Alpine pauses only that tree, reports rejected promises through its error handler, and continues initialization after every promise settles.

Verification

  • npm run build
  • Focused Cypress coverage: deferred initialization, clone, mutation, and x-ignore (27 passing)
  • The Level 1 commit also builds independently.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant