Summary#
Babel and JS tooling report source positions in UTF-16 code units, but Rust strings are indexed by UTF-8 bytes. Using Babel offsets to slice a Rust &str produces wrong spans or panics the moment any non-ASCII character appears earlier in the file. The fix is to convert UTF-16 offsets to UTF-8 byte offsets before slicing.
Problem#
React's Rust compiler used Babel's SourceLocation.index (UTF-16 units) to slice a Rust &str (UTF-8 bytes). ASCII-only files worked fine; any non-ASCII character before the slice point caused an out-of-bounds panic.
Solution#
Walk the source string to convert the UTF-16 code-unit offset to a UTF-8 byte index before slicing. Alternatively, maintain a pre-built lookup table from UTF-16 → UTF-8 offsets for the whole file.
Failure Modes#
- Bug is invisible in ASCII-only test suites
- Offset is wrong (not panicking) when the slice happens to land on a valid UTF-8 boundary, silently extracting incorrect identifiers
- Only manifests in production code that includes non-ASCII identifiers or comments
Sources#
- https://github.com/Comfy-Org/ComfyUI/pull/16275
- https://github.com/Comfy-Org/ComfyUI/pull/16250
- https://github.com/Comfy-Org/ComfyUI/pull/16232
- https://github.com/Comfy-Org/ComfyUI/pull/16261
- https://github.com/Comfy-Org/ComfyUI/pull/16218
- https://github.com/Comfy-Org/ComfyUI/pull/16267
- https://github.com/Comfy-Org/ComfyUI/pull/16229
- https://github.com/Comfy-Org/ComfyUI/pull/16233
- https://github.com/GitHubDaily/GitHubDaily/pull/267
- https://github.com/GitHubDaily/GitHubDaily/pull/52
- https://github.com/react/react/pull/37579
- https://github.com/react/react/pull/37574
- https://github.com/react/react/pull/37513
- https://github.com/react/react/pull/37573
- https://github.com/react/react/pull/37213
- https://github.com/react/react/pull/37554
- https://github.com/react/react/pull/37550
- https://github.com/react/react/pull/37539
- https://github.com/react/react/pull/37549
- https://github.com/react/react/pull/37547
- https://github.com/thedaviddias/Front-End-Checklist/pull/737
- https://github.com/thedaviddias/Front-End-Checklist/pull/664
- mined_at: 2026-09-12T06:50:40Z
Sagwan Revalidation 2026-09-12T07:34:48Z#
- verdict:
ok - note: UTF-16↔UTF-8 오프셋 불일치 문제와 해법은 2026년에도 변함없이 유효한 기술 사실이다.
Sagwan Revalidation 2026-09-16T01:25:53Z#
- verdict:
refresh - note: 핵심 교훈은 유효하지만 Sources가 주제와 불일치하고 불완전하다