Skip to content

[StimulusBundle] Add applications to load a distinct set of controllers per AssetMapper entrypoint - #4020

Open
Prometee wants to merge 4 commits into
symfony:3.xfrom
Prometee:stimulus-assetmapper-applications
Open

Prometee wants to merge 4 commits into
symfony:3.xfrom
Prometee:stimulus-assetmapper-applications

Conversation

@Prometee

@Prometee Prometee commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor
Q A
Bug fix? no
New feature? yes
Deprecations? no
Documentation? yes
Issues Fix #2321
License MIT

With AssetMapper, StimulusBundle compiles one loader from the global controller_paths and assets/controllers.json. Every entrypoint that starts Stimulus gets all of these controllers: eager controllers of one area, such as the admin, are imported and preloaded on the pages of another area. Webpack Encore and Reprise can already use a different set of controllers per build. AssetMapper cannot.

This PR adds the stimulus.applications option. Each application gets its own module, compiled by the bundle, which only imports and preloads the controllers of the application. The global @symfony/stimulus-bundle loader keeps working as before.

Example with an admin area:

assets/
  app.js                       # global entrypoint, unchanged
  controllers/
    hello_controller.js        # global controller
  admin.js                     # admin entrypoint
  admin/
    stimulus.js                # admin module
    controllers/
      dashboard_controller.js  # admin controller
# config/packages/stimulus.yaml
stimulus:
    applications:
        admin: ~

With the conventions, admin: ~ is the same as:

# config/packages/stimulus.yaml
stimulus:
    applications:
        admin:
            loader: '%kernel.project_dir%/assets/admin/stimulus.js'
            controller_paths:
                - '%kernel.project_dir%/assets/admin/controllers'
            include_global: true

The admin pages then load dashboard and hello; the other pages only load hello.

// assets/admin/stimulus.js: replaced at compile time, gives editors and TypeScript the types
export { startStimulusApp } from '@symfony/stimulus-bundle';
// assets/admin.js: the entrypoint, the only importmap.php entry
import { startStimulusApp } from './admin/stimulus.js';

startStimulusApp();

Options of an application:

  • loader (default assets/<name>/stimulus.js): the module of the application, inside an AssetMapper path. It must be empty or contain only the stub above; any other content fails compilation.
  • controller_paths (default: the controllers/ directory next to the module, when it exists and is not a global controller path): controllers of the application. They override controllers with the same name from the global paths and from controllers.json.
  • include_global (default true): also load the global controller_paths and the global controllers.json. With false, the application only gets its own controllers and its own controllers_json, if any.
  • controllers_json (default null): a file with the same format as assets/controllers.json, replacing the global file for the application.
  • merge_controllers_json (default false): merge the application file over the global one instead of replacing it. Requires controllers_json and include_global: true.

For assets stored outside assets/, only the module has to be configured: the controllers are loaded from the controllers/ directory next to it.

Assets in assets/ (default)Assets in frontend/
assets/
  admin.js
  admin/
    stimulus.js
    controllers/
      dashboard_controller.js
frontend/
  admin.js
  admin/
    stimulus.js
    controllers/
      dashboard_controller.js
# config/packages/stimulus.yaml
stimulus:
    applications:
        admin: ~
# config/packages/stimulus.yaml
stimulus:
    applications:
        admin:
            loader: '%kernel.project_dir%/frontend/admin/stimulus.js'
Controllers loaded from assets/admin/controllers/Controllers loaded from frontend/admin/controllers/

An isolated admin, with neither the global controllers nor the global UX packages, and its own Chart.js controller:

# config/packages/stimulus.yaml
stimulus:
    applications:
        admin:
            include_global: false
            controllers_json: '%kernel.project_dir%/assets/admin/controllers.json'
// assets/admin/controllers.json
{
    "controllers": {
        "@symfony/ux-chartjs": {
            "chart": { "enabled": true, "fetch": "lazy" }
        }
    }
}

The admin pages then load dashboard and, on first use, chart; hello and the global UX packages are not loaded.

Before After
Modules One loader for all entrypoints One module per application, plus the global loader
Controllers on the admin pages All global controllers Only the controllers of the admin application
controllers.json One global file Global file, none (include_global: false), or a file per application that replaces or merges over it

Implementation notes:

  • The startup code moved from loader.js to @symfony/stimulus-bundle/runtime.js. The compiler writes the controller list directly into loader.js and into each application module, so the global loader has the same preloads as before. dist/controllers.js is still compiled for code importing it directly; its deprecation will be proposed separately.
  • The configuration is checked when the container is built: application names must match [a-z][a-z0-9_-]* (default is reserved), the module must be an existing .js file not shared by two applications, and an application controllers_json file must exist.
  • When at least one application is configured, a file containing only the stub that no application uses fails compilation, since served as is it would start the global application. Without applications, such files are not inspected.
  • The module depends on the controller directories and controllers.json files of its application, so adding or editing a controller recompiles it; the container is rebuilt when the convention controllers/ directory appears.
  • Applications are an AssetMapper feature. With Symfony 8.2's importmap_entries: reachable, the import map is scoped per application as well.
  • Symfony Flex only updates the global assets/controllers.json. Application files with controllers_json have to be updated by hand. The documentation says so.

Thanks @smnandre for the alternative implementation this PR is now based on.

@carsonbot carsonbot added Documentation Improvements or additions to documentation Feature New Feature StimulusBundle Status: Needs Review Needs to be reviewed labels Sep 30, 2026
@github-actions

github-actions Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

📊 Packages dist files size difference

Thanks for the PR! Here is the difference in size of the packages dist files between the base branch and the PR.
Please review the changes and make sure they are expected.

FileBefore (Size / Gzip)After (Size / Gzip)
StimulusBundle
loader.d.ts 362 B / 196 B 184 B-49% 📉 / 153 B-22% 📉
loader.js 3.01 kB / 981 B 306 B-90% 📉 / 174 B-82% 📉
runtime.d.ts Added 479 B / 209 B
runtime.js Added 2.97 kB / 963 B

@Prometee
Prometee force-pushed the stimulus-assetmapper-applications branch from 997bd80 to fd2503d Compare September 30, 2026 16:13
@Kocal
Kocal requested review from kbond and smnandre October 1, 2026 05:08
@Kocal

Kocal commented Nov 5, 2026

Copy link
Copy Markdown
Member

I feel like symfony/symfony#54377 is somewhere related to your request.

@smnandre

Copy link
Copy Markdown
Member

Hi Francis,

Thanks a lot for tackling this! Scoping controllers per area has been requested for a long time (#2321), and your PR gets the hard part right: one compiled module per application, reusing the controller map generator, with the global loader left untouched.

While testing it locally, I ended up building an alternative implementation on top of your commit:

smnandre/ux@fd2503d...sa/stimulus-applications-alt

In one sentence: the application module is a project file, so I treated it like one, and made the isolated mode really isolate the area.

What it changes:

  • admin: ~ is enough: assets/admin/stimulus.js and assets/admin/controllers/ by convention, loader and controller_paths still override them
  • the entrypoint imports ./admin/stimulus.js with a relative path: no importmap.php entry, no @symfony/stimulus-bundle/admin name for a project file
  • the module holds a one-line stub (types for editors) replaced at compile time; any other content, or a stub that no application uses, fails compilation instead of being silently ignored
  • loader.js is compiled directly: no extra glue module, same preloads as on 3.x
  • include_global_paths: false (renamed include_global) also drops the global controllers.json, so an isolated admin no longer gets Map or any other global UX package
  • UX packages per area with controllers_json, replacing or merged over the global file

Eager and lazy controllers work per application, as does the reachable import map mode of Symfony 8.2. The tests check preloads and import map entries on every page, both what must be there and what must not.

More details in a second comment. Curious to hear what you think, and feel free to take whatever is useful!

@smnandre

Copy link
Copy Markdown
Member

Context: what AssetMapper does per page

importmap('admin') renders two things:

Both follow the import graph. With a single global loader, every entrypoint reaches every controller, so neither helps. Applications give each area its own graph, which is what makes preloads, and the reachable mode, scoped per area.

Three issues

The import name. @symfony/stimulus-bundle/admin reads like a sub-module shipped by the bundle, while it points to a file of the project, declared by the project in importmap.php. Each area needs that manual entry, and the boundary between vendor and application code gets blurry.

The extra loader. loader.js is split into core.js, controllers.js and a 3-line loader.js that glues them. In the end that glue adds nothing at runtime: the compiler can write the controller list directly into the module it compiles, which is what the application modules already do.

An isolation leak. include_global_paths: false drops the global controller directories, but the global controllers.json still applies: every UX package enabled there, Map included, is still loaded in an "isolated" area.

The idea

Treat the application module like any other project file: it lives in the project, the entrypoint imports it with a relative path, and the bundle replaces its content at compile time. The global loader.js gets the same treatment, so both modules have the same shape and import only the runtime and their own controllers.

An application needs three files:

# config/packages/stimulus.yaml
stimulus:
    applications:
        admin: ~   # assets/admin/stimulus.js + assets/admin/controllers/
// assets/admin/stimulus.js: replaced at compile time, gives editors and TypeScript the types
export { startStimulusApp } from '@symfony/stimulus-bundle';
// assets/admin.js: the entrypoint, the only importmap.php entry
import { startStimulusApp } from './admin/stimulus.js';

startStimulusApp();

What AssetMapper serves for assets/admin/stimulus.js:

import { loadControllers, startApplication } from "../@symfony/stimulus-bundle/runtime.js";
import controller_0 from "./controllers/dashboard_controller.js";
export const eagerControllers = {"dashboard": controller_0};
export const lazyControllers = {"report": () => import("./controllers/report_controller.js")};
export const isApplicationDebug = true;
export const startStimulusApp = () => startApplication(eagerControllers, lazyControllers, isApplicationDebug);
export { loadControllers };

Eager and lazy work as with the global loader: eager controllers are imported and preloaded, lazy ones (stimulusFetch: 'lazy' or "fetch": "lazy" in controllers.json) are loaded with import() on first use and never preloaded. Any content other than the stub (or an empty file) fails compilation instead of being silently overwritten, and so does a stub that no application uses, which would otherwise start the global application.

Use cases

The examples below use this project:

assets/
  controllers.json           # enables @symfony/ux-autocomplete and @symfony/ux-map (eager)
  controllers/
    hello_controller.js      # eager
    chart_controller.js      # lazy
  admin/controllers/
    dashboard_controller.js  # eager
    report_controller.js     # lazy

Default: no applications

Nothing to configure, nothing changes from 3.x.

Page Eager (preloaded) Lazy
importmap('app') hello, autocomplete, map chart

An admin area

stimulus:
    applications:
        admin: ~

An application inherits the global controllers and the global controllers.json. The admin controllers never reach the public pages, but every UX package enabled globally is in both:

Page Eager (preloaded) Lazy
importmap('app') hello, autocomplete, map chart
importmap('admin') dashboard, hello, autocomplete, map report, chart

Map everywhere except the admin

Keep everything global, and disable Map for the admin only, with an admin file merged over the global one:

stimulus:
    applications:
        admin:
            controllers_json: '%kernel.project_dir%/assets/admin/controllers.json'
            merge_controllers_json: true
// assets/admin/controllers.json
{ "controllers": { "@symfony/ux-map": { "map": { "enabled": false } } } }
Page Eager (preloaded) Lazy
importmap('app') hello, autocomplete, map chart
importmap('admin') dashboard, hello, autocomplete report, chart

The merge works per controller and per key: the admin file only overrides what it sets. A package Flex adds later to the global file reaches the admin too.

An isolated admin

include_global: false (include_global_paths in the PR) now means nothing global: neither the global controllers nor the UX packages of the global controllers.json.

stimulus:
    applications:
        admin:
            include_global: false
Page Eager (preloaded) Lazy
importmap('app') hello, autocomplete, map chart
importmap('admin') dashboard report

An isolated admin with its own Map

The admin declares the UX controllers it wants in its own controllers.json, with its own settings: here Map is lazy in the admin and stays eager everywhere else.

stimulus:
    applications:
        admin:
            include_global: false
            controllers_json: '%kernel.project_dir%/assets/admin/controllers.json'
// assets/admin/controllers.json
{ "controllers": { "@symfony/ux-map": { "map": { "enabled": true, "fetch": "lazy" } } } }
Page Eager (preloaded) Lazy
importmap('app') hello, autocomplete, map chart
importmap('admin') dashboard report, map

For Map in the admin only, also set "enabled": false in the global file. Flex only writes to the global file, so a package installed later must be added to the admin file by hand.

No default application

Every page belongs to an area: a front and an admin, no app entrypoint. The global controller_paths and controllers.json then act as the shared base of both areas; set include_global: false on an area that shares nothing. The global loader is never imported, so it never reaches a page.

stimulus:
    applications:
        front: ~   # assets/front/stimulus.js + assets/front/controllers/ (menu)
        admin: ~
Page Eager (preloaded) Lazy
importmap('front') menu, hello, autocomplete, map chart
importmap('admin') dashboard, hello, autocomplete, map report, chart

Shared controllers

To share a directory between some areas only, list it in each of them. An area reusing assets/admin/controllers gets those controllers, not the admin module.

stimulus:
    applications:
        admin:
            controller_paths:
                - '%kernel.project_dir%/assets/admin/controllers'
                - '%kernel.project_dir%/assets/shared/controllers'   # notify (eager)
        shop:
            controller_paths:
                - '%kernel.project_dir%/assets/shop/controllers'     # cart (eager)
                - '%kernel.project_dir%/assets/shared/controllers'
            include_global: false
Page Eager (preloaded) Lazy
importmap('admin') dashboard, notify, hello, autocomplete, map report, chart
importmap('shop') cart, notify

When two controllers have the same name, the application one wins over the global one, which wins over a UX package.

Under the hood

What gets replaced, and what does not. The entrypoint (assets/admin.js) is a regular module, never touched. What changes is the module it imports, assets/admin/stimulus.js: AssetMapper serves generated code in place of its content. The file on disk is never modified.

Who replaces it. StimulusLoaderJavaScriptCompiler, an AssetMapper compiler (asset_mapper.compiler tag) that already compiled the controller list on 3.x. It now handles three source files, matched by realpath:

Source file Compiled with Result
dist/loader.js (global, @symfony/stimulus-bundle) the global controller map runtime import + global list
each application module (assets/admin/stimulus.js...) the controller map of that application runtime import + list of the application
dist/controllers.js the global controller map list only, kept for code importing it directly

When. Whenever AssetMapper builds the asset. In dev, on the first request that needs it, then from the AssetMapper cache until a dependency changes. In prod, once, when asset-map:compile writes public/assets/admin/stimulus-<hash>.js.

Order. The compiler runs at priority 100, before JavaScriptImportPathCompiler. That one parses the imports of the generated code, so AssetMapper records the runtime and the controllers as dependencies of the module: they become preloads (eager) or reachable entries (lazy). The import of the stub is never seen; at a lower priority it would be, and the admin page would pull the global loader and all its controllers.

The runtime import. The generated code imports runtime.js (former core.js) with a path relative to the module, so the module needs no import map entry and works from any directory or AssetMapper path.

Cache. The compiled module depends on the controller directories and the controllers.json files of its application: adding, removing or editing a controller recompiles it. For the convention directory, a FileExistenceResource rebuilds the container when assets/<name>/controllers appears, and the module also watches the parent directory, since a missing directory cannot be watched.

Configuration. loader and controller_paths default to null in the config tree; the extension resolves assets/<name>/stimulus.js and assets/<name>/controllers, and fails early when the module is missing. With include_global: false, the application gets neither the global directories nor the global controllers.json.

Guards. Before replacing the content, the compiler checks that the module is empty or holds the stub only. Anything else fails with a message pointing to the entrypoint, instead of being silently dropped. The compiler also catches the stub in a file that no application uses (a typo in stimulus.yaml, an application removed from the config): served as is, it would import the global loader and start the global application without any error.

Outside AssetMapper. dist/loader.js keeps a valid source (runtime + controllers.js) for unit tests or any tool that reads it uncompiled.

Recap

  • admin: ~ instead of two required paths; loader and controller_paths still override the convention
  • relative import, no importmap.php entry, no bundle-looking specifier
  • loader.js compiled directly: one module less on every page (12 preloads, as on 3.x)
  • core.js renamed runtime.js
  • eager and lazy unchanged, per application
  • include_global: false isolates for real: no global controllers, no global UX packages
  • UX packages per area with controllers_json, replaced or merged; Flex still writes only to the global file
  • stub for types, guards against lost code and against an undeclared stub
  • include_global_paths renamed include_global, since it now covers controllers.json too

Compatibility

Applications are an AssetMapper feature. The controller list is built on the PHP side, by the AssetMapper compiler of the bundle, from controller_paths and controllers.json. With Webpack Encore or Reprise, the bundler builds that list in Node at build time: the compiler never runs, and applications has no effect. Both already scope controllers per area their own way, as documented in the bundle:

  • Webpack Encore: one entry per area, each calling startStimulusApp() from @symfony/stimulus-bridge with its own require.context();
  • Reprise (Vite, Rsbuild): one build per area, with its own controllersJson and controllersDir, registered under reprise.builds.

The bundle requires Symfony 7.4 or later.

Scoping preloads does not depend on the Symfony version. Scoping the import map does:

Symfony 7.4 to 8.1 Symfony 8.2+
Preloads and downloads per area yes yes
Lazy controllers loaded on first use yes yes
Import map limited to the area no: every importmap.php entry is listed yes, with importmap_entries: reachable

Without reachable, the import map of an admin page still lists the front entries (symfony/symfony#54377). These are only URLs: nothing is downloaded unless something imports it. The reachable mode (symfony/symfony#65622) is opt-in, the default stays all:

# config/packages/asset_mapper.yaml (Symfony 8.2+)
asset_mapper:
    importmap_entries: reachable

Tested against the lowest dependencies (symfony/asset-mapper 7.4.0, symfony/framework-bundle 7.4.23), where the reachable test is skipped, and against symfony/asset-mapper 8.2.x-dev.

@smnandre

Copy link
Copy Markdown
Member

PS: thanks to Claude, for understanding my ideas, constraints and problems..
... and for making me look like someone who can explain them clearly 😆

@Prometee
Prometee force-pushed the stimulus-assetmapper-applications branch from fd2503d to e35dca6 Compare November 23, 2026 21:44
@Prometee

Copy link
Copy Markdown
Contributor Author

Thanks a lot @smnandre for the thorough review and for building an alternative on top of my commit, it's really helpful.

I agree with the three issues you raised:

  • Import name: a relative import of a project file is cleaner than a @symfony/stimulus-bundle/admin specifier, and it removes the manual importmap.php entry.
  • Extra module: compiling loader.js directly is better than the glue module. I had noted the extra preload as a cost, your approach removes it.
  • Isolation: you're right, keeping the global controllers.json with include_global_paths: false was intentional but misleading. include_global covering both makes more sense, and the feature isn't released yet, so it's the right time to settle it.

The admin: ~ convention, the core.js → runtime.js rename and the guard on the content of an application module are welcome too.

Two changes I'd like to propose on top of your branch:

  1. Convention for the controllers: instead of hardcoding assets/<name>/controllers, could controller_paths default to dirname(loader)/controllers? A project outside assets/ would then only set loader, and the convention would read as "controllers live next to the module", whatever the AssetMapper paths are. The docs would describe this default and show an example with a module outside assets/.

  2. Orphan-stub guard: it currently reads every small non-vendor .js asset in supports(), even when no application is configured. A project that already has a file re-exporting startStimulusApp from @symfony/stimulus-bundle would fail compilation after a 3.x minor update, without using the feature. Could we only enable that check when at least one application is configured? Typos in the application name are already caught by the extension (missing module), so the remaining case is mostly a removed application.

And two minor points:

  • dist/controllers.js is still compiled although nothing imports it anymore. I'd keep it as-is here and propose its deprecation in a separate PR, if that works for you.
  • The CHANGELOG entry should be 3.6 rather than 3.9.

If you agree, I'll pull your two commits into this PR (with you as co-author), apply the points above, add a test for a module outside assets/, and update the PR description. Or would you rather open your own PR?

@smnandre

Copy link
Copy Markdown
Member

Thank you @Prometee !

Really glad it helps, and great to see we land on the same page 😄

Both of your suggestions make sense to me:

  1. controller_paths defaulting to dirname(loader)/controllers is a better way to put it: same result for the default case, and "controllers live next to the module" is easier to explain than a path tied to assets/ (Good call on the example outside assets)
  2. Fully agree on the orphan-stub guard. Reading small files in supports() for a feature nobody configured is a cost for everyone, and a 3.x minor update should never break a project that does not use it. Enabling it only when at least one application is configured is the right trade-off.

Deprecating dist/controllers.js in a separate PR sounds good to me!

One thing on the CHANGELOG: 3.6, 3.7 and 3.8 are already released, so the entry does belong to 3.9 (yeah I know, PR was opened back in September, so 3.6 was right at the time...)

And of course, take the commits, with pleasure, that's what they're there for! #oss

@smnandre

Copy link
Copy Markdown
Member

Thanks a lot @Prometee!

One last thing, and it's my fault: I merged the "Use stubs for mocks" commit separately in #4351, so it now conflicts with 3.x.

Could you rebase on 3.x and drop that commit? (keep your version of StimulusLoaderJavaScriptCompilerTest.php when resolving)

The rebase also fixes the "App Demo Native" job, which #4352 repaired on 3.x.

Prometee and others added 4 commits November 25, 2026 11:18
…rs per AssetMapper entrypoint

| Q              | A
| -------------- | ---
| Bug fix?       | no
| New feature?   | yes
| Deprecations?  | no
| Documentation? | yes
| Issues         | symfony#2321
| License        | MIT

With AssetMapper, StimulusBundle compiles one loader from the global `controller_paths` and `assets/controllers.json`. Every entrypoint that starts Stimulus gets all of these controllers. Eager controllers of one area, such as the admin, are imported and preloaded on the pages of another area. Webpack Encore and Reprise can already use a different set of controllers per build. AssetMapper cannot.

This PR adds the `stimulus.applications` option. Each application compiles its own loader, and that loader only imports and preloads the controllers of the application. The global `@symfony/stimulus-bundle` loader is unchanged.

```yaml
stimulus:
    applications:
        admin:
            loader: '%kernel.project_dir%/assets/admin/stimulus_loader.js'
            controller_paths: ['%kernel.project_dir%/assets/admin/controllers']
            include_global_paths: false
            controllers_json: '%kernel.project_dir%/assets/admin/controllers.json'
            merge_controllers_json: false
```

```php
// importmap.php
'admin' => ['path' => './assets/admin.js', 'entrypoint' => true],
'@symfony/stimulus-bundle/admin' => ['path' => './assets/admin/stimulus_loader.js'],
```

```js
// assets/admin.js
import { startStimulusApp } from '@symfony/stimulus-bundle/admin';

startStimulusApp();
```

Options of an application:

- `loader` (required): an empty `.js` file inside an AssetMapper path. The bundle replaces its content when the asset is compiled. Each application needs its own file.
- `controller_paths` (default `[]`): controllers of the application. They override controllers with the same name from the global paths and from `controllers.json`.
- `include_global_paths` (default `true`): also load the controllers of the global `controller_paths`.
- `controllers_json` (default `null`): a file with the same format as `assets/controllers.json`. When set, it replaces the global file for the application. When `null`, the application uses the global file.
- `merge_controllers_json` (default `false`): merge the application file over the global one instead of replacing it. A controller not listed in the application file keeps its global settings. For a listed controller, `enabled`, `fetch` and `name` override the global values. `autoimport` entries are merged by path. `"enabled": false` removes a controller from the application. This option requires `controllers_json`.

| | Before | After |
| --- | --- | --- |
| Loaders | One loader for all entrypoints | One loader per application, plus the unchanged global loader |
| Controllers on the admin pages | All global controllers | Only the controllers of the `admin` application |
| `controllers.json` | One global file | Global file, or a file per application that replaces or merges over it |

Implementation notes:

- The startup code moved from `loader.js` to a new `@symfony/stimulus-bundle/core.js` module. It does not import any controller list. `loader.js` and each application loader import it with their own controllers. Importing `loader.js` from an application loader would also import the global `controllers.js`, so all global controllers would be preloaded again. The exports of `loader.js` (`startStimulusApp`, `loadControllers`) do not change.
- `core.js` is a new module, so it appears in the importmap and in the preloads of every page that uses the global loader.
- Application loaders use the same `ControllersMapGenerator` as the global loader, so their controllers are sorted by name as introduced in symfony#3703 (for symfony#3562), and their digest stays stable between builds.
- The configuration is checked when the container is built. Application names must match `[a-z][a-z0-9_-]*`, and `default` is reserved. The loader must be an existing `.js` file, and a loader cannot be used by two applications. These checks run after parameter resolution and on the real path of the file. An application `controllers_json` file must exist.
- When a `controllers.json` file refers to an unknown package or controller, the error message now names the file that was read.
- Symfony Flex only updates the global `assets/controllers.json`. With `merge_controllers_json: false`, the application files have to be updated by hand. The documentation says so.
…check orphan stubs only with applications

Co-authored-by: Simon André <smn.andre@gmail.com>
@Prometee
Prometee force-pushed the stimulus-assetmapper-applications branch from 6b16e6a to 33d7824 Compare November 25, 2026 10:19
@Prometee

Copy link
Copy Markdown
Contributor Author

Done @smnandre: rebased on 3.x and dropped "Use stubs for mocks". The only conflict was in StimulusLoaderJavaScriptCompilerTest.php, where I kept the version of this PR; it already uses stubs, so nothing from #4351 is lost. The CI is green, "App Demo Native" included.

@Prometee

Copy link
Copy Markdown
Contributor Author

I feel like symfony/symfony#54377 is somewhere related to your request.

@Kocal Yes, they're complementary: symfony/symfony#54377 is about the import map listing every entry, fixed in Symfony 8.2 by importmap_entries: reachable (symfony/symfony#65622). This PR scopes the controllers each entrypoint imports and preloads. With a single global loader every entrypoint reaches every controller, so reachable can't filter them; with applications, each area has its own graph, and on 8.2+ reachable scopes the import map per area too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Documentation Improvements or additions to documentation Feature New Feature Status: Needs Review Needs to be reviewed StimulusBundle

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[StimulusBundle] Conditional Loading of Stimulus Controllers Based on Configuration

4 participants