You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug #81 [Bug] Removing unnecessary Promise in object of controllers to be loaded (weaverryan)
This PR was squashed before being merged into the main branch.
Discussion
----------
[Bug] Removing unnecessary Promise in object of controllers to be loaded
Hi!
Subtle change. Previously, the webpack loader parsed `controllers.json` (which eventually becomes the `symfonyControllers` variable in `index.ts`) into something that exported an object where each key was a promise - something like:
```js
export default {
'symfony--ux-autocomplete--autocomplete': import(/* webpackMode: \"eager\" */ '`@symfony`/ux-autocomplete/dist/controller.js')
}
```
Then, in `startStimulusApp()`, we called used `.then()` to wait for that promise to resolve then registered its resolved value:
```js
symfonyControllers[controllerName].then((module) => {
application.register(controllerName, module.default);
});
```
This is totally unnecessary and a relic of how this library was originally built. It also causes the UX controllers to be registered *late*. It's barely noticeable, but in practice, instead of the UX controllers being registered BEFORE the DOM is ready, they are registered after. This actually causes a problem with a new feature from LiveComponents.
The new parsed version of `controllers.json` from the loader looks much simpler:
```diff
+ import controller_0 from '`@symfony`/ux-autocomplete/dist/controller.js';
export default {
- 'symfony--ux-autocomplete--autocomplete': import(/* webpackMode: \"eager\" */ '`@symfony`/ux-autocomplete/dist/controller.js')
+ 'symfony--ux-autocomplete--autocomplete': controller_0,
}
```
(I don't show it here, but lazy controllers have a similar simplification).
In short: it's a bug fix & an easy win. Controllers will load slightly earlier as a result.
Thanks!
Commits
-------
0d77e41 [Bug] Removing unnecessary Promise in object of controllers to be loaded
thrownewError('Your controllers.json file was not found. Be sure to add a Webpack alias from "@symfony/stimulus-bridge/controllers.json" to *your* controllers.json file.');
38
35
}
39
36
if('undefined'===typeofconfig['controllers']){
40
37
thrownewError('Your Stimulus configuration file (assets/controllers.json) lacks a "controllers" key.');
41
38
}
39
+
letcontrollerIndex=0;
42
40
for(constpackageNameinconfig.controllers){
43
41
letpackageConfig;
44
42
try{
@@ -58,24 +56,19 @@ function createControllersModule(config) {
0 commit comments