Skip to content

[Stimulus] Detect preserved /*! ... */ lazy comments and lock deterministic ordering - #10

Merged
Kocal merged 1 commit into
symfony:mainfrom
Kocal:stimulus-preserved-lazy-comment-and-deterministic-order
Jul 10, 2026
Merged

[Stimulus] Detect preserved /*! ... */ lazy comments and lock deterministic ordering#10
Kocal merged 1 commit into
symfony:mainfrom
Kocal:stimulus-preserved-lazy-comment-and-deterministic-order

Conversation

@Kocal

@Kocal Kocal commented Jul 10, 2026

Copy link
Copy Markdown
Member
Q A
Bug fix? yes
New feature? no
Deprecations? no
Issues -
License MIT

Reprise's Stimulus virtual module (assets/src/core/stimulus.ts) reimplements StimulusBundle's ControllersMapGenerator for bundlers, since the webpack loader Encore relied on doesn't exist outside webpack. StimulusBundle just merged two small fixes to that PHP generator, so this PR ports both to the TS side. Two commits, one per upstream PR.

1. Detect the preserved /*! stimulusFetch: 'lazy' */ comment form (port of symfony/ux#3702)

A controller opts into lazy loading by adding a stimulusFetch: 'lazy' comment above its class. The problem: tsc and esbuild strip regular block comments during minification, but keep "preserved" ones written as /*! ... */. Reprise's lazy-detection regex only matched the plain /* ... */ form, so the marker was lost as soon as the controller went through a minifying build. This adds the optional ! to the block-comment branch so both forms are detected. New fixture controller + test included.

2. Sort local controllers for a deterministic loader output (port of symfony/ux#3703)

Upstream, controllers were iterated in filesystem order, so the generated loader (and its content hash) could shift between builds even with no actual change, breaking cache busting. Reprise already sorts its local controllers (listLocalControllers ends with .sort()), so there's no behavior change here. This commit just adds a regression test that pins the exact emission order, plus a comment explaining why the sort matters.

All tests pass (assets/test), and oxlint/oxfmt are clean. Added a short docs note in doc/index.rst for the preserved-comment form.

@Kocal Kocal changed the title [Stimulus] Detect preserved /*! ... */ lazy comments and lock deterministic ordering [Stimulus] Detect preserved /*! ... */ lazy comments and lock deterministic ordering Jul 10, 2026
@Kocal Kocal added the Bug Something isn't working label Jul 10, 2026
@Kocal
Kocal force-pushed the stimulus-preserved-lazy-comment-and-deterministic-order branch from 9b74e6a to 16caeb7 Compare July 10, 2026 16:43
@Kocal
Kocal merged commit 0fe1df4 into symfony:main Jul 10, 2026
@Kocal
Kocal deleted the stimulus-preserved-lazy-comment-and-deterministic-order branch July 10, 2026 16:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant