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

chore: register stimulus controllers from plugins #3608

Merged
merged 3 commits into from
Jan 28, 2025

Conversation

adrianthedev
Copy link
Collaborator

@adrianthedev adrianthedev commented Jan 25, 2025

Description

This PR adds the ability to auto-register StimulusJS controllers from plugins.
See how https://github.com/avo-hq/marksmith is achieving that.

This PR:

  • adds the ability to register Stimulus controllers in plugins with Avo.asset_manager.register_stimulus_controller "marksmith", "MarksmithController"
  • the controllers are outputted to a special window.Avo object
  • there's a new late-registration file which picks them up and registers them in the current application
  • the Stimulus Controller class is being assigned to the window object so it can be used by the plugin controllers in order to not bundle it with the plugin resulting in duplicated code (StimulusJS)

Checklist:

  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works

Screenshots & recording

Manual review steps

  1. Install https://github.com/avo-hq/marksmith
  2. Observe how it auto-registers the controllers and the JS works out of the box.

Manual reviewer: please leave a comment with output from the test if that's the case.

@github-actions github-actions bot added the Chore label Jan 25, 2025
Copy link

codeclimate bot commented Jan 25, 2025

Code Climate has analyzed commit 98fd9ed and detected 0 issues on this pull request.

View more on Code Climate.

@adrianthedev adrianthedev self-assigned this Jan 27, 2025
@adrianthedev adrianthedev merged commit 36b510f into main Jan 28, 2025
20 checks passed
@adrianthedev adrianthedev deleted the chore/add-stimulus-controllers-from-plugins branch January 28, 2025 08:34
Copy link
Contributor

This PR has been merged into main. The functionality will be available in the next release.

Please check the release guide for more information.

@xeron
Copy link

xeron commented Jan 30, 2025

@adrianthedev I'm getting this error after avo update:

11:12:06 web.1  | ActionView::Template::Error (Asset `late-registration.js` was not declared to be precompiled in production.
11:12:06 web.1  | Declare links to your assets in `app/assets/config/manifest.js`.
11:12:06 web.1  |
11:12:06 web.1  |   //= link late-registration.js
11:12:06 web.1  |
11:12:06 web.1  | and restart your server):
11:12:06 web.1  |
11:12:06 web.1  | Causes:
11:12:06 web.1  | Sprockets::Rails::Helper::AssetNotPrecompiledError (Asset `late-registration.js` was not declared to be precompiled in production.
11:12:06 web.1  | Declare links to your assets in `app/assets/config/manifest.js`.

@adrianthedev
Copy link
Collaborator Author

Please downgrade for now. We'll come out with a hotfix soon

@Paul-Bob
Copy link
Contributor

@xeron this issue was fixed and released on 3.16.4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants