Commit 0fe1df4
committed
bug #10 [Stimulus] Detect preserved
This PR was squashed before being merged into the main branch.
Discussion
----------
[Stimulus] Detect preserved `/*! ... */` lazy comments and lock deterministic ordering
| 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.
Commits
-------
16caeb7 [Stimulus] Detect preserved `/*! ... */` lazy comments and lock deterministic ordering/*! ... */ lazy comments and lock deterministic ordering (Kocal)4 files changed
Lines changed: 43 additions & 6 deletions
File tree
- assets
- src/core
- test
- core
- fixtures/stimulus/controllers
- doc
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
54 | 54 | | |
55 | 55 | | |
56 | 56 | | |
| 57 | + | |
| 58 | + | |
57 | 59 | | |
58 | | - | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
| |||
173 | 175 | | |
174 | 176 | | |
175 | 177 | | |
176 | | - | |
177 | | - | |
178 | | - | |
179 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
180 | 186 | | |
181 | 187 | | |
182 | 188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
62 | 69 | | |
63 | 70 | | |
64 | 71 | | |
| |||
78 | 85 | | |
79 | 86 | | |
80 | 87 | | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
81 | 108 | | |
82 | 109 | | |
83 | 110 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
119 | 119 | | |
120 | 120 | | |
121 | 121 | | |
122 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
123 | 125 | | |
124 | 126 | | |
125 | 127 | | |
| |||
0 commit comments