symfony/stimulus-bundle
Symfony bundle that integrates Stimulus with Symfony and Symfony UX. Adds Twig stimulus_* helpers for controllers/actions/targets, supports AssetMapper, and provides a service to build Stimulus data attributes for use in templates and services.
stimulus_controller, stimulus_action) to embed Stimulus behavior directly in templates, reducing manual JS and improving maintainability.StimulusHelper service allows dynamic generation of Stimulus data attributes from PHP services, enabling tight coupling between backend logic and frontend behavior (e.g., passing Symfony entities to Stimulus controllers).| Risk | Severity | Mitigation |
|---|---|---|
| Symfony Version Lock | High | Requires Symfony 7.4+ (v3.0.0) or 6.4+ (v2.x). Audit compatibility early. |
| AssetMapper Dependency | Medium | May require migration from Webpack Encore to AssetMapper for full feature support. Test locally first. |
| Twig Template Changes | Medium | Audit templates for inline JS (onclick, addEventListener) and replace with stimulus_* functions. |
| Stimulus Learning Curve | Low | Provide team training on Stimulus controllers/actions/targets (low barrier to entry). |
| Debugging Complexity | Low | Use Symfony Profiler + Browser DevTools for Stimulus actions. Log events via console.log in controllers. |
| PHP 8.4+ Requirement | High | Upgrade PHP if using v3.0.0 (or stick to v2.x for PHP 8.2). |
| TypeScript Support | Low | Optional; vanilla JS works fine for most use cases. |
onclick, addEventListener) that need replacement?data-controller, data-action)?stimulus_controller_link_tags, ux_controller_link_tags).stimulus_controller with .ts files).stimulus_* functions. Ensure templates use {{ stimulus_controller('name') }} instead of manual JS.| Phase | Task | Tools | Risks |
|---|---|---|---|
| 1. Prep | Audit Symfony version, PHP, and asset pipeline. | composer require symfony/stimulus-bundle |
Version conflicts |
| 2. Setup | Install bundle, configure config/packages/stimulus.yaml. |
symfony console debug:config stimulus |
Misconfiguration |
| 3. Template Migration | Replace inline JS with stimulus_* Twig functions. |
grep -r "onclick=" templates/ |
Template breaks |
| 4. Controller Development | Write Stimulus controllers (JS/TS) in assets/controllers/. |
VS Code + Stimulus extension | Debugging issues |
| 5. Asset Pipeline | Migrate to AssetMapper if using Webpack Encore. | symfony console assets:install |
Build failures |
| 6. Testing | Test Stimulus actions with Symfony Profiler. | bin/phpunit + Browser DevTools |
Edge cases |
| 7. Rollout | Deploy to staging, monitor performance. | New Relic/Sentry | User-facing bugs |
ux_controller_link_tags (v2.x) or stimulus_controller_link_tags (v3.0.0) for UX packages.encore.addEntry() manually.stimulus_* Twig functions in new templates.excluded_patterns).symfony console debug:config stimulus to verify config.data-action triggers).How can I help you explore Laravel packages today?