Skip to content
Source
Sign inSign up
TanStack/highlight

fix: handle large script interpolations without argument overflow #56

Mergedtannerlinsleymerged 1 commit intomain fromtaren/highlight-large-interpolationsmerged by tannerlinsley

tannerlinsleycommented

Changes

A template interpolation with 140,000 numeric terms can exceed Node's function argument limit while highlighting. Append its mapped ranges by iteration instead of spreading them into a call, preserving the existing mapping and range order. Bun already completes the baseline.

Add a regression for JavaScript, TypeScript, JSX and TSX that fails on the released baseline, plus an interior-gap assertion for the existing large Markdown regression.

Validation

All 12 local gates pass, including 383 tests, type checking, build, package and packed-package checks, all 66 size profiles and 20 runtime budgets. Exact public and semantic output matches 48,168 cases each on Node and Bun. Raw ranges match 40,128 cases and 256 controlled reentry cases each, across all four scanner modes.

This is a robustness fix. Failed baseline work is never used for speed comparisons. Two completed-work comparisons show a 0.7–1.1% Node time cost for a working interpolation fixture, and three allocation measurements show a 1.3–1.8% sampled-allocation cost. Ordinary docs and many-template controls stay near neutral. Twenty fresh startup pairs put the combined 10,000-term interpolation and 1,000-template workload at 11.56 to 11.73 ms of first work. Retained heap does not increase materially.

The all-language bundle is 78,505 minified / 27,804 gzip / 24,843 Brotli bytes. Docs are 15,776 / 6,310 / 5,791. Octane is 14,081 / 5,800 / 5,312, exactly at its existing gzip limit. The pending C composition also passes unchanged budgets at 79,158 / 27,986 / 24,925. No API, dependency, language support or budget changes.

Summary by CodeRabbit

  • Bug Fixes
    • Syntax highlighting now handles very large template interpolations in JavaScript, TypeScript, JSX, and TSX without failing.
    • Inline code highlighting remains accurate in large Markdown documents, including content appearing far into the document.
    1. 🦋 Changeset detected

      Latest commit: 813d33a1259510ff2cc799d799353eec06e957f7

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 1 package
      NameType
      @tanstack/highlightPatch

      Not sure what this means? Click here to learn what changesets are.

      Click here if you're a maintainer who wants to add another changeset to this PR

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      No actionable comments were generated in the recent review.

      Recent review info
      Run configuration
      • Source mode: Auto
      • Repository: Unavailable
      • Branch: Unavailable
      • File: No configuration file from this repository applied
      • Commit: Unavailable
      • Layers: defaults
      • Review profile: CHILL
      • Plan: Advanced
      • Run ID: 46709ba8-33e4-417c-8b3f-50be593198d8
      Commits

      Reviewing files that changed from the base of the PR and between f090d9155869cf2b6facd5b05502fb99a14fba4b and 813d33a1259510ff2cc799d799353eec06e957f7.

      Files selected for processing: 4
      • .changeset/large-script-interpolations.md
      • src/internal/script.ts
      • test/markdown-large-embedded.test.ts
      • test/script-large-interpolation.test.ts

      Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

      Walkthrough

      The change appends template interpolation ranges individually and adds regression coverage for large interpolations across JavaScript, TypeScript, JSX, and TSX. It also adjusts a large Markdown fixture and adds an interior range assertion.

      Changes: Large interpolation range handling

      Layer / File(s)Summary
      Append interpolation ranges and validate large inputs
      src/internal/script.ts, test/script-large-interpolation.test.ts, test/markdown-large-embedded.test.ts, .changeset/large-script-interpolations.md
      Interpolation ranges are appended one at a time instead of being spread into a single push call. Tests cover 140,000-term interpolations across four script tokenizers and an interior range in a large Markdown fixture. The changeset records the patch.

      Estimated code review effort: 2 (Simple) | ~10 minutes

      Change: Bug fix

      Possibly related PRs

      • TanStack/highlight#54: Addresses the JavaScript argument-limit failure for large Markdown fence range lists.
      • TanStack/highlight#52: Addresses the same argument-limit failure when markup appends embedded-language ranges.
      Merge Risk: Minimal · up to 813d3

      The change addresses large interpolation failures; no merge-blocking issue was identified.

      Pre-merge checks: Passed 4 · Failed 1
      Failed Failed checks: 1 warning
      Check nameStatusExplanationResolution
      Docstring CoverageWarningDocstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…Write docstrings for the functions missing them to satisfy the coverage threshold.
      Passed Passed checks: 4 passed
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely describes the main fix for large script interpolations and argument overflow.
      Description checkPassedThe description includes both required sections. It explains the change, its purpose, focused regression tests, validation results, performance measurements, and size budgets.
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Full details: Docstring Coverage

      Explanation

      Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 1 functions across 3 files. (1 skipped: 1 unsupported.)

      Resolution

      Write docstrings for the functions missing them to satisfy the coverage threshold.

      Finishing Touches
      Generate docstrings
      • Commit to this branch
      • Create a new PR
      Generate unit tests (beta)
      • Commit to this branch
      • Create a new PR
      • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

      Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

      Share
    3. @coderabbitai review

    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Action performed

      Review finished.

      Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

    5. tannerlinsley merged thisb1891d2

    6. tannerlinsley closed this

Sign in to join this conversation.