Skip to content

fix(snippets): don't compile the root Description union on Windows - #1071

Merged
ChronosSF merged 1 commit into
vnextfrom
sstoychev/fix-snippet-schema-windows-overflow
Nov 16, 2026
Merged

ChronosSF merged 1 commit into
vnextfrom
sstoychev/fix-snippet-schema-windows-overflow

Conversation

@ChronosSF

Copy link
Copy Markdown
Member

Since #1058, every local generate / xplat:dev:* run on Windows fails in the json-snippet schema check:

RangeError: Maximum call stack size exceeded
    at new Function (<anonymous>)
    at Ajv.compileSchema (node_modules/ajv/dist/compile/index.js:89:30)
    at Ajv.inlineOrCompile ...
    at Ajv.resolveRef ...

Linux CI passes on the same commit.

Cause

schemaValidator registers the whole emitted schema with ajv, then compiles one validator per type with { $ref: 'snippets#/definitions/<Type>' }. The first time ajv resolves a $ref into a registered schema, it compiles that schema's root first. The root's descriptions/* pattern refers to #/definitions/Description, which is an anyOf over every description type.

ajv compiles an anyOf as one nested if (!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:webcomponents serves /charts/types/sankey-chart and /charts/types/vertical-chart with a 200.
  • On its own, the old registration overflows on the first DataChart compile. 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 install doesn't update it, and a beta.16 build rejects the Sankey and vertical series as unknown properties:

cd docs/xplat/scripts/snippet-emitter
npm ci && npm run build

🤖 Generated with Claude Code

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 gmurray81 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 inside definitions point 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.

@ChronosSF
ChronosSF merged commit f2d1966 into vnext Nov 16, 2026
14 checks passed
@ChronosSF
ChronosSF deleted the sstoychev/fix-snippet-schema-windows-overflow branch November 16, 2026 14:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants