fix: chunk large JCEF messages to prevent JetBrains sidebar freezes (#11899)
* fix: chunk large JCEF messages to prevent JetBrains sidebar freezes When session data exceeds ~1MB (e.g. long conversations with many context items), sendToWebview embeds the entire JSON payload in a single executeJavaScript call. JCEF's JS parser/compiler cannot handle source strings that large and freezes the IDE. This adds a chunked sending path: payloads over 1MB are base64-encoded, split into 512KB chunks sent as individual executeJavaScript calls that each append to a buffer variable, then a final call decodes and dispatches the reassembled message via window.postMessage. Each individual call is trivial for JCEF to parse, and V8 handles the string concatenation and final JSON.parse without issue. Messages under 1MB (the vast majority) take the existing fast path unchanged. * chore: trim verbose comments * fix: clean up partial chunk buffer on failure * fix: use array join instead of string concat for JCEF chunk reassembly Replaces O(n²) string concatenation (+=) with O(n) array push + join for JS-side chunk buffering. Extracts script generation into testable buildChunkScripts() and adds unit tests for chunking logic. * perf: increase chunk size from 512KB to 2MB Reduces IPC round-trips by 4x (e.g. 7 calls instead of 26 for 10MB). Safe because chunks are trivial JS with pure Base64 string literals. * fix: decode chunked messages as UTF-8 to prevent mojibake atob() returns Latin-1, so multi-byte UTF-8 characters (em dashes, accented letters, CJK, emoji) were mangled. Use TextDecoder to properly decode UTF-8 bytes after base64 decoding.
D
Dallin Romney committed
afd5e5e18f7f5d3a010d59aacbfaa06d5ce12f10
Parent: afb6b21
Committed by GitHub <noreply@github.com>
on 3/26/2026, 9:59:21 PM