Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit stimulus-reflex:ready event on element instead of document #625

Conversation

marcoroth
Copy link
Member

@marcoroth marcoroth commented Jan 16, 2023

Type of PR

Enhancement

Description

Previously the stimulus-reflex:ready was invoked every time the scanForReflexes() function was called. With the recent changes of being able to load Stimulus controllers async we can't guarantee that the stimulus-reflex:ready was always triggered at the right moment in time and it wasn't guaranteed that all controllers were actually loaded and registered.

Since we can't guarantee that the "whole document and all controllers are loaded and ready", we instead emit an event on the actual element that we know that it is ready and was setup for sure.

Resolves #608

Why should this be added

Consistently and better support for asynchronous loading of Stimulus controllers.

Checklist

  • My code follows the style guidelines of this project
  • Checks (StandardRB & Prettier-Standard) are passing
  • This is not a documentation update

@marcoroth marcoroth changed the title Emit `stimulus reflex ready event on element Emit stimulus-reflex:ready event on element instead of document Jan 16, 2023
@marcoroth marcoroth merged commit d773570 into stimulusreflex:master Jan 18, 2023
@marcoroth marcoroth deleted the emit-stimulus-reflex-ready-event-on-element branch January 18, 2023 22:17
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.

stimulus-reflex:ready event should only be emitted once per page load
1 participant