[9.2] [DevTools Console] Avoid editor freeze after pasting large JSON (#251173)#254618
Merged
kapral18 merged 3 commits intoelastic:9.2from Feb 27, 2026
Merged
[9.2] [DevTools Console] Avoid editor freeze after pasting large JSON (#251173)#254618kapral18 merged 3 commits intoelastic:9.2from
kapral18 merged 3 commits intoelastic:9.2from
Conversation
8f8fa9f to
3a2ceb7
Compare
c00451b to
f8c3b88
Compare
…tic#251173) Closes elastic#251172 This PR fixes a DevTools Console editor freeze that occurs after pasting very large request payloads (notably JSON containing huge string fields) by removing expensive, full-buffer operations from keystroke-time paths and by preventing a super-linear ES|QL context scan from running on large inputs. https://github.com/user-attachments/assets/54b90fdb-f0b0-4de0-ae53-6fa4a12a98d9 Console language) **What changed** - The Console completion provider no longer calls `model.getValue()` to compute `textBeforeCursor`. - ES|QL context detection is only attempted when the cursor is within a `POST /_query` (or `POST _query/async`) request. - When it *is* a `_query` request, the provider reads only the relevant slice via `model.getValueInRange()` (from the request line to the cursor). - For all other requests (or when no request line is found within a bounded lookback), completion delegates to the existing actions provider. **Why** - `model.getValue()` materializes the entire document string, which becomes prohibitively expensive after users paste very large payloads; doing that on completion triggers (often on every keystroke) is enough to stall the UI. - ES|QL completion only makes sense for `_query` requests; scoping the work avoids paying the cost for non-ES|QL traffic. **Why this approach** - We preserve existing completion behavior by delegating to the actions provider, but avoid the pathological cost by restricting work to a small, semantically relevant window. (`checkForTripleQuotesAndEsqlQuery`) **What changed** - `checkForTripleQuotesAndEsqlQuery` was rewritten to scan the text once and avoid repeated substring+regex work inside the main loop. **Why** - The previous approach could become super-linear on adversarial inputs (many quotes / many potential toggles), which is exactly what large JSON payloads tend to contain. - In the worst case, this turns “type one character” into “do a huge amount of CPU work”, producing the freeze. **Why this approach** - A single forward scan preserves semantics while making the runtime scale predictably with input size. keystroke (`shared-ux` React Monaco editor) **What changed** - The `onDidChangeModelContent` handler computes the next value by applying `event.changes` to a shadow string (`lastKnownValueRef`) instead of calling `editor.getValue()`. - Controlled-mode syncing (`useLayoutEffect`) first compares the incoming `value` against the shadow value to avoid unnecessary full-buffer reads. **Why** - `editor.getValue()` materializes the full buffer; doing it on every keystroke creates a hard O(N) cost per change, which is visible (and can be catastrophic) for large models. - Applying incremental changes keeps the per-keystroke cost proportional to the change set, not the document size. **Why this approach** - Monaco already provides the exact edit deltas (`IModelContentChangedEvent.changes`). Applying those deltas is the cheapest way to keep React state in sync without forcing full-buffer reads. - **`language.test.ts`**: exercises the completion provider branching/delegation so we don’t regress behavior while tightening when/what we read from the model. - **`autocomplete_utils.test.ts`**: focused behavioral coverage for ES|QL context detection edge cases (the perf-worker regression test was removed to keep the suite deterministic and low-maintenance). - **`editor.test.tsx`**: verifies the incremental `onChange` value computation (including multi-change ordering) and controlled sync behavior. - `node scripts/jest.js src/platform/packages/shared/kbn-monaco/src/languages/console/language.test.ts src/platform/packages/shared/kbn-monaco/src/languages/console/utils/autocomplete_utils.test.ts --config src/platform/packages/shared/kbn-monaco/jest.config.js` - `node scripts/jest.js src/platform/packages/shared/shared-ux/code_editor/impl/react_monaco_editor/editor.test.tsx --config src/platform/packages/shared/shared-ux/code_editor/impl/jest.config.js` Co-authored-by: Cursor <cursoragent@cursor.com>
Avoid flaky CodeEditor interactions when entering custom samples. Update routing preview specs to validate syntax editor reflects conditions without editing JSON directly. Also fix the Scout page object API usage so tests don’t access the private `page` field (TypeScript typecheck). Refs: elastic#255025, elastic#255029 Made-with: Cursor
f8c3b88 to
7b0c3b4
Compare
Contributor
Author
I rebased and pushed the changes. Thanks |
Ensure the custom samples editor helper re-reads and validates JSON after the slow-typing retry, so we don't clear a successful attempt and fail the test. Made-with: Cursor
Contributor
💛 Build succeeded, but was flaky
Failed CI StepsThe CI Stats report is too large to be displayed here, check out the CI build annotation for this information. History
|
ElenaStoeva
approved these changes
Feb 27, 2026
Contributor
ElenaStoeva
left a comment
There was a problem hiding this comment.
Console changes lgtm, tested locally
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Backport
This will backport the following commits from
mainto9.2:CI / Scout note (9.2 Streams)
This backport branch was repeatedly failing
streams_appScout tests on 9.2 due to a pre-existing Playwright/MonacoCodeEditorinteraction where bulk input (notably.fill()) can leave the editor content truncated/garbled. Downstream, the Streams condition syntax editor silently ignores invalid JSON, so conditions/previews never apply.To stabilize CI test-side only (no product behavior changes):
Follow-ups
@kbn/code-editor: improve Monaco/Playwright bulk input reliability)Test plan
node scripts/scout.js run-tests --arch stateful --domain classic --testFiles x-pack/platform/plugins/shared/streams_app/test/scout/ui/tests/data_management/data_processing/data_sources_management.spec.ts,x-pack/platform/plugins/shared/streams_app/test/scout/ui/tests/data_management/data_routing/routing_data_preview.spec.tsQuestions ?
Please refer to the Backport tool documentation