Files
ltbxd-actorle/assets/bootstrap.js
thibaud-leclere 9cb5c6e2a5
Some checks failed
Build and Push Docker Images / Build app image (push) Failing after 17s
Build and Push Docker Images / Build database image (push) Successful in 8s
Build and Push Docker Images / Build node image (push) Failing after 17s
fix: use vite-plugin-symfony Stimulus loader and wrap react_component in div
The @symfony/stimulus-bundle loader generates an empty controllers.js,
so Stimulus controllers from controllers.json (including ux-react) were
never registered. Switching to vite-plugin-symfony/stimulus/helpers
uses the virtual:symfony/controllers module that properly reads
controllers.json. Also wrap react_component() output in a <div> since
it only renders data-attributes, not a full HTML element.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-28 15:02:27 +01:00

20 lines
870 B
JavaScript

import { startStimulusApp } from 'vite-plugin-symfony/stimulus/helpers';
const app = startStimulusApp();
// Register React components for {{ react_component() }} Twig function.
// We register them manually because @symfony/ux-react's registerReactControllerComponents
// expects Webpack's require.context API, which is not available in Vite.
const reactControllers = import.meta.glob('./react/controllers/**/*.jsx', { eager: true });
window.resolveReactComponent = (name) => {
const key = `./react/controllers/${name}.jsx`;
const module = reactControllers[key];
if (!module) {
const available = Object.keys(reactControllers)
.map(k => k.replace('./react/controllers/', '').replace('.jsx', ''));
throw new Error(`React controller "${name}" does not exist. Possible values: ${available.join(', ')}`);
}
return module;
};