Commit d8cca00
fix: resolve Alpine.js MutationObserver race condition in observability sub-views (#3967)
* fix: resolve Alpine.js MutationObserver race condition in observability sub-views
When observability sub-partials (Tools, Metrics, Prompts, Resources) are
dynamically loaded via fetch(), Alpine.js's MutationObserver auto-initializes
x-data components before the inline <script> tags defining their controllers
have executed, causing 'createToolsController is not defined' errors.
Move script extraction logic to a native <script> block (browser-executed,
not Alpine's new Function() evaluator):
- Extract <script> blocks from raw HTML via regex (new RegExp with string
concatenation avoids </script> literal breaking HTML parsing)
- Execute via document.createElement('script').text + appendChild
(jQuery globalEval pattern — synchronous, global scope)
- Insert clean (script-free) HTML inside Alpine.mutateDom() to suppress
MutationObserver, then call Alpine.initTree() explicitly
Fixes #3966
Signed-off-by: Olivier Gintrand <olivier.gintrand@forterro.com>
* test(ui): add unit tests for observability __obsExecAndStrip helper
Add vitest/jsdom tests covering the script extraction, execution,
and Alpine.mutateDom + initTree injection pattern introduced in
the observability dashboard race condition fix.
Covers: script ordering, attribute handling, error recovery, cleanup,
controller factory simulation, and Alpine fallback paths.
Ref: #3967
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
* fix(ui): harden Alpine guard and warn on unsupported external scripts
Address review feedback on the observability race-condition fix:
- Harden Alpine.js guard to check typeof mutateDom/initTree === 'function'
before calling, consistent with initialization.js pattern (L956, L1505).
- Detect and warn on <script src="..."> in dynamic partials instead of
silently dropping them. No sub-partials currently use external scripts.
- Update __obsExecAndStrip regex to capture attributes separately for
the src detection.
- Add 5 new tests: external script warning, partial Alpine API fallback
(mutateDom missing, initTree missing, non-function values).
- Add drift-risk note to test file header.
Ref: #3967
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
* fix(ui): prevent false-positive src detection on data-src attributes
The \bsrc\s*= regex matched data-src= because - is a word boundary,
causing inline scripts with data-src attributes to be silently skipped.
Use (?:^|\s)src\s*= to require whitespace before src, avoiding
false positives on data-src, ng-src, or similar hyphenated attributes.
Add regression test for data-src false-positive case.
Ref: #3967
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
---------
Signed-off-by: Olivier Gintrand <olivier.gintrand@forterro.com>
Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
Co-authored-by: Olivier Gintrand <olivier.gintrand@forterro.com>
Co-authored-by: Mihai Criveti <crivetimihai@gmail.com>1 parent 697b9bb commit d8cca00
2 files changed
Lines changed: 433 additions & 77 deletions
File tree
- mcpgateway/templates
- tests/unit/js
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
17 | 44 | | |
18 | 45 | | |
19 | 46 | | |
| |||
79 | 106 | | |
80 | 107 | | |
81 | 108 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
101 | 119 | | |
| 120 | + | |
| 121 | + | |
102 | 122 | | |
103 | 123 | | |
104 | 124 | | |
| |||
149 | 169 | | |
150 | 170 | | |
151 | 171 | | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
170 | | - | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
171 | 178 | | |
| 179 | + | |
| 180 | + | |
172 | 181 | | |
173 | 182 | | |
174 | 183 | | |
| |||
219 | 228 | | |
220 | 229 | | |
221 | 230 | | |
222 | | - | |
223 | | - | |
224 | | - | |
225 | | - | |
226 | | - | |
227 | | - | |
228 | | - | |
229 | | - | |
230 | | - | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
236 | | - | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
241 | 237 | | |
| 238 | + | |
| 239 | + | |
242 | 240 | | |
243 | 241 | | |
244 | 242 | | |
| |||
289 | 287 | | |
290 | 288 | | |
291 | 289 | | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
311 | 296 | | |
| 297 | + | |
| 298 | + | |
312 | 299 | | |
313 | 300 | | |
314 | 301 | | |
| |||
0 commit comments