Create scripts added to the registry later at their declared index - #9202
Conversation
Build size reportThis PR changes the size of the minified bundles.
|
mvaligursky
left a comment
There was a problem hiding this comment.
Automated PR review by Codex (GPT-5).
I found one ordering-state issue and one documentation-placement issue. The predecessor-based insertion works for the covered ordinary names and registration/move cases, but _scriptsIndex is not a sufficient durable declaration-order record for every supported name or after cloning the moved state through #9200.
The submitted focused suite passed (90 tests), ESLint and git diff --check passed, and all current GitHub checks are green. Two targeted probes failed: integer-like names were reordered, and a source/clone diverged when #9200 was combined with this PR after moving the predecessor.
| */ | ||
| _awaitingInsertIndex(scriptName) { | ||
| let previous = null; | ||
| for (const name in this._scriptsIndex) { |
There was a problem hiding this comment.
[P1] Track declaration order explicitly instead of deriving it from this object. JavaScript enumerates integer-like keys before other string keys, and such script names are currently accepted: declaring ['scriptA', '10', '2', 'scriptB'] on this head ultimately produced ['2', '10', 'scriptA', 'scriptB']. There is also a cross-PR failure with #9200: declare A, B, X(awaiting), move B to index 0, clone, then register X; this helper gives the source [B, X, A], while the clone reconstructed from the stale ind becomes [B, A, X]. Please retain/clone a stable declaration sequence (or otherwise make both reconstruction and deferred insertion share one source of truth).
| * @param {number} scriptsLength - The length of the scripts array. | ||
| * @private | ||
| */ | ||
| /** |
There was a problem hiding this comment.
[P3] Move the new helper and its JSDoc above the existing _insertScriptInstance JSDoc. As written, two documentation blocks are consecutive, so the original Inserts script instance... block is orphaned and _insertScriptInstance no longer has the parameter documentation that immediately preceded it.
1ea157f to
c591e2a
Compare
|
Both fixed, and the PR is now stacked on #9200 so the two share one ordering rule. P1 — you were right that P3 — the helper and its JSDoc now sit above the |
mvaligursky
left a comment
There was a problem hiding this comment.
Automated re-review by Codex (GPT-5).
Re-reviewed the updated commit stacked on #9200. No actionable issues found.
Both previous findings are resolved: insertion now derives from the explicit stable declaration sequence supplied by #9200, covering integer-like names and move/clone/register parity, and the helper JSDoc no longer orphans _insertScriptInstance documentation. The focused stacked ScriptComponent suite passed (96 tests); changed-file ESLint, diff validation, and all current CI checks are green.
c591e2a to
5b5782d
Compare
5dcc235 to
64fe7e0
Compare
5b5782d to
d389a6c
Compare
64fe7e0 to
fa1aa39
Compare
d389a6c to
f079bfc
Compare
When a script is declared before its script type is registered, the awaiting entry stores `ind`, the number of script instances the component had at that moment. The deferred sweep in ScriptRegistry#add then creates the instance at that index, but by then other awaiting scripts may have been created and shifted the array, and consecutive awaiting scripts all captured the same index. Registering the types of `a, b, c, d, e, f`, where `b`, `c` and `e` were awaiting, produced `a, c, e, b, d, f`. Derive the index when the script is actually created instead, from the same declaration order the clone is rebuilt from: the script belongs directly after the script it was declared after, skipping the ones that do not exist yet. That gives the declared order for any registration order, and follows the preceding script if it has since been moved. The awaiting entry keeps `ind`, it is no longer read by the engine but is part of the shape of `_scriptsIndex` entries. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
f079bfc to
2521ba8
Compare
Description
When a script is declared before its script type is registered, the awaiting entry stores
ind— the number of script instances the component had at that moment:The deferred sweep in
ScriptRegistry#addthen creates the instance at that index. By then other awaiting scripts may already have been created and shifted the array, and consecutive awaiting scripts all captured the same index. So the declared order is not preserved. Reproduces with no cloning involved — declaringa, b, c, d, e, fwithb,c,eawaiting, then registering their types:Fix
Derive the index when the script is actually created, from the
_declarationOrderrecord #9200 added and rebuilds a clone from: the script belongs directly after the script it was declared after, skipping the ones that do not exist yet. That gives the declared order for any registration order, and — unlike a captured index — follows the preceding script if it has since beenmove()d.Sharing one rule with the clone reconstruction is what keeps a source and its clone converging on the same order: with two different mechanisms, cloning a component that had been reordered and still had a script pending gave the source
[B, X, A]and the clone[B, A, X].The awaiting entry keeps
ind. It is no longer read by the engine, but it is part of the shape of_scriptsIndexentries.Last of the awaiting-script fixes after #9200 and #9201.
Testing
Three tests in
test/framework/components/script/component.test.mjs, all three fail onmain:Checklist
🤖 Generated with Claude Code