Repository navigation
fix(snippets): don't compile the root Description union on Windows - #1071
Conversation
schemaValidator registered the whole emitted schema with ajv. The first
$ref into it makes ajv compile the schema's root, which reaches
#/definitions/Description: an anyOf over every description type. ajv
nests one block per branch, and at the 897 branches the
igniteui-webcomponents-core 7.1.1-beta.19 emitter produces, compiling
that code overflows V8's parser stack on Windows ("Maximum call stack
size exceeded"). Every local xplat generate and dev run on Windows
fails; Linux CI has the headroom and passes.
Nothing validates against the root: validators are compiled per type.
Registering only the definitions keeps the union from being compiled.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
gmurray81
left a comment
There was a problem hiding this comment.
I checked this against vnext on macOS (Node 24.16), using the beta.19 snippet emitter and the pinned examples checkout. I was looking at two things: does it bring back the slow validation that inlineRefs: false fixed, and could it let a bad snippet pass?
Validation results are unchanged
- All 348 real snippets pass under both versions.
- I made 581 broken copies of those snippets: an unknown property at the top level, a wrong-typed value, and an unknown property on a nested child such as a series. Both versions flag all 581, with identical messages.
- This is expected from the schema's structure. It has no
$id, and all 76,831$refs insidedefinitionspoint at other definitions. Only the root (descriptions/*) references#/definitions/Description, and nothing validates against the root.
Less compile work, not more
inlineRefs: false is kept, and ajv now generates less code. I counted the functions it builds through new Function:
| vnext | this PR | |
|---|---|---|
| Functions generated | 1,908 | 515 |
| Deepest nesting in generated code | 898 | 129 |
| Checking every snippet | 5.5 s | 4.3 s |
The 898-level function is the Description union. On vnext it's compiled as soon as the first type is.
Stack headroom
Running the check with a smaller V8 stack (--stack-size):
| V8 stack size | vnext | this PR |
|---|---|---|
| 400 KB | ok | ok |
| 350 to 200 KB | overflow | ok |
| 150 KB and below | overflow | overflow |
vnext only just fits, which explains why only some Windows machines and Node versions hit the crash. This change roughly halves the stack the check needs.
One suggestion
If a later emitter adds a definition that references Description (a property that accepts any component, say), that type's validator would compile the union again. The result would be the same overflow, not a silent pass. It might be worth a sentence in the comment so whoever hits it knows where to look.
Looks good to me.
Since #1058, every local
generate/xplat:dev:*run on Windows fails in the json-snippet schema check:Linux CI passes on the same commit.
Cause
schemaValidatorregisters the whole emitted schema with ajv, then compiles one validator per type with{ $ref: 'snippets#/definitions/<Type>' }. The first time ajv resolves a$refinto a registered schema, it compiles that schema's root first. The root'sdescriptions/*pattern refers to#/definitions/Description, which is ananyOfover every description type.ajv compiles an
anyOfas one nestedif (!valid) {block per branch. The beta.19 emitter that #1058 moved to produces 897 branches. Compiling that code overflows V8's parser stack on Windows.Fix
Register only
{ $schema, definitions }with ajv. Nothing validates against the root, so the union is no longer compiled. Each per-type validator still resolves its own#/definitions/...refs.generated/snippet-schema.json, which backs editor completion, is still written from the full schema.Verified (Windows, Node 24.22.1)
node docs/xplat/scripts/generate.mjs --platform=WebComponents:185 checked against the schema, all valid(crashed before the change).npm run xplat:dev:webcomponentsserves/charts/types/sankey-chartand/charts/types/vertical-chartwith a 200.DataChartcompile. The new one compiles all 67 types the snippets use in about 6s.Separate local step, not part of this PR
After pulling #1058, rebuild the snippet emitter. Root
npm installdoesn't update it, and a beta.16 build rejects the Sankey and vertical series as unknown properties:🤖 Generated with Claude Code