-
Notifications
You must be signed in to change notification settings - Fork 4.4k
fix: chunk large JCEF messages to prevent JetBrains sidebar freezes #11899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8691401
fix: chunk large JCEF messages to prevent JetBrains sidebar freezes
RomneyDa ee9cdc2
chore: trim verbose comments
RomneyDa 73eadd5
fix: clean up partial chunk buffer on failure
RomneyDa 7c0b4e7
fix: use array join instead of string concat for JCEF chunk reassembly
RomneyDa 2035f41
perf: increase chunk size from 512KB to 2MB
RomneyDa ea1039c
fix: decode chunked messages as UTF-8 to prevent mojibake
RomneyDa e5e7c0a
Merge branch 'main' into fix/jcef-chunked-messages
RomneyDa 850b4c9
merge: resolve conflict with main, keep chunking + isClosed guard
RomneyDa File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
.../kotlin/com/github/continuedev/continueintellijextension/unit/ContinueBrowserChunkTest.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package com.github.continuedev.continueintellijextension.unit | ||
|
|
||
| import com.github.continuedev.continueintellijextension.browser.ContinueBrowser | ||
| import com.github.continuedev.continueintellijextension.browser.ContinueBrowser.Companion.buildChunkScripts | ||
| import junit.framework.TestCase | ||
| import java.util.Base64 | ||
|
|
||
| class ContinueBrowserChunkTest : TestCase() { | ||
|
|
||
| fun `test small message produces single chunk`() { | ||
| val json = """{"messageType":"test","data":"hello"}""" | ||
| val scripts = buildChunkScripts(json, "buf1") | ||
|
|
||
| assertEquals(1, scripts.chunks.size) | ||
| assertReassemblesTo(json, scripts.chunks, "buf1") | ||
| } | ||
|
|
||
| fun `test message splits into expected number of chunks`() { | ||
| val json = """{"data":"${"x".repeat(2_000_000)}"}""" | ||
| val chunkSize = ContinueBrowser.CHUNK_SIZE | ||
| val encoded = Base64.getEncoder().encodeToString(json.toByteArray(Charsets.UTF_8)) | ||
| val expectedChunks = (encoded.length + chunkSize - 1) / chunkSize | ||
|
|
||
| val scripts = buildChunkScripts(json, "buf2") | ||
|
|
||
| assertEquals(expectedChunks, scripts.chunks.size) | ||
| assertReassemblesTo(json, scripts.chunks, "buf2") | ||
| } | ||
|
|
||
| fun `test custom chunk size`() { | ||
| val json = """{"data":"${"a".repeat(100)}"}""" | ||
| val scripts = buildChunkScripts(json, "buf3", chunkSize = 32) | ||
|
|
||
| assertTrue(scripts.chunks.size > 1) | ||
| assertReassemblesTo(json, scripts.chunks, "buf3") | ||
| } | ||
|
|
||
| fun `test init script creates array buffer`() { | ||
| val scripts = buildChunkScripts("{}", "myId") | ||
| assertEquals("""window.__cc=window.__cc||{};window.__cc["myId"]=[];""", scripts.init) | ||
| } | ||
|
|
||
| fun `test finalize script joins and decodes`() { | ||
| val scripts = buildChunkScripts("{}", "myId") | ||
| assertTrue(scripts.finalize.contains("""window.__cc["myId"].join("")""")) | ||
| assertTrue(scripts.finalize.contains("atob")) | ||
| assertTrue(scripts.finalize.contains("TextDecoder")) | ||
| assertTrue(scripts.finalize.contains("JSON.parse")) | ||
| assertTrue(scripts.finalize.contains("""delete window.__cc["myId"]""")) | ||
| } | ||
|
|
||
| fun `test cleanup script deletes buffer`() { | ||
| val scripts = buildChunkScripts("{}", "myId") | ||
| assertEquals("""delete window.__cc["myId"];""", scripts.cleanup) | ||
| } | ||
|
|
||
| fun `test special characters survive base64 round-trip`() { | ||
| val json = """{"data":"héllo wörld 日本語 emoji: 🎉 quotes: \"nested\""}""" | ||
| val scripts = buildChunkScripts(json, "buf4", chunkSize = 32) | ||
|
|
||
| assertReassemblesTo(json, scripts.chunks, "buf4") | ||
| } | ||
|
|
||
| fun `test exact chunk boundary`() { | ||
| // Create a JSON string whose Base64 encoding is exactly 2x chunkSize | ||
| val chunkSize = 64 | ||
| val target = chunkSize * 2 | ||
| // Base64 output is ceil(input/3)*4, so we need input = target * 3 / 4 bytes | ||
| val payloadSize = target * 3 / 4 | ||
| val json = "x".repeat(payloadSize) | ||
| val encoded = Base64.getEncoder().encodeToString(json.toByteArray(Charsets.UTF_8)) | ||
|
|
||
| assertEquals(target, encoded.length) | ||
|
|
||
| val scripts = buildChunkScripts(json, "buf5", chunkSize = chunkSize) | ||
| assertEquals(2, scripts.chunks.size) | ||
| assertReassemblesTo(json, scripts.chunks, "buf5") | ||
| } | ||
|
|
||
| /** | ||
| * Simulates the JS-side reassembly: extract push payloads, join, base64-decode, | ||
| * and verify the result matches the original JSON. | ||
| */ | ||
| private fun assertReassemblesTo(expectedJson: String, chunkScripts: List<String>, bufferId: String) { | ||
| val pushPrefix = """window.__cc["$bufferId"].push("""" | ||
| val pushSuffix = """");""" | ||
|
|
||
| val reassembled = chunkScripts.joinToString("") { script -> | ||
| assertTrue("Chunk should use array push", script.startsWith(pushPrefix)) | ||
| assertTrue(script.endsWith(pushSuffix)) | ||
| script.removePrefix(pushPrefix).removeSuffix(pushSuffix) | ||
| } | ||
|
|
||
| val decoded = String(Base64.getDecoder().decode(reassembled), Charsets.UTF_8) | ||
| assertEquals(expectedJson, decoded) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.