Skip to content

[Console] Fix JSON highlighting inconsistencies for nested objects#255426

Merged
kapral18 merged 1 commit intoelastic:mainfrom
kapral18:fix/console/fix-highlighting-inconsistencies-245820
Mar 2, 2026
Merged

[Console] Fix JSON highlighting inconsistencies for nested objects#255426
kapral18 merged 1 commit intoelastic:mainfrom
kapral18:fix/console/fix-highlighting-inconsistencies-245820

Conversation

@kapral18
Copy link
Copy Markdown
Contributor

@kapral18 kapral18 commented Mar 2, 2026

Addresses #245820

Summary

  • Fixes an issue in Dev Tools Console where closing nested braces incorrectly returned the lexer to the root state, breaking syntax highlighting for subsequent elements.

Root Cause

  • The lexer rules matched any } to return to the root state, which caused it to pop out of the JSON context prematurely when encountering nested objects.

Fix

  • Updated the rule to only return to the root state when an unindented closing brace ends the line (/^}\s*/), keeping nested braces highlighted properly without state changes.
  • Added tests to cover nested objects highlighting and avoid stack limit issues.

Screenshots

Before

console_highlight_before

After

console_highlight_after

Test Plan

  • Run tests: yarn test:jest src/platform/packages/shared/kbn-monaco/src/languages/console/lexer_rules/shared.test.ts
  • Manual verification:
    1. Open the Dev Tools Console in Kibana.
    2. Paste the following request with nested JSON objects (as shown in the screenshots):
      PUT console_highlight_bug_test2
      {
        "mappings": {
          "properties": {
            "body": {
              "properties": {
                "properties": {
                  "properties": {
                    "structured": {
                      "type": "object",
                      "subobjects": false
                    },
                    "text": {
                      "type": "match_only_text"
                    }
                  }
                },
                "event_name": {
                  "type": "keyword"
                },
                "host": {
                  "properties": {
                    "name": {
                      "type": "alias",
                      "path": "resource.attributes.host.name"
                    }
                  }
                }
              }
            }
          }
        }
      }
    3. Verify that the syntax highlighting remains consistent and doesn't break (turn un-highlighted text/white) after the first nested closing brace }. Properties like "text", "event_name" and "host" should retain their correct coloring.

Release note

Fixes an issue in Dev Tools Console where closing nested braces broke syntax highlighting for subsequent elements.

Addresses an issue in the Dev Tools Console where closing nested braces
incorrectly returned the lexer to the root state, breaking syntax
highlighting for subsequent elements. It changes the rule to only return
to the root state when an unindented closing brace ends the line,
keeping nested braces highlighted properly without state changes.

Made-with: Cursor
@kapral18 kapral18 requested a review from a team as a code owner March 2, 2026 03:11
@kapral18 kapral18 added release_note:fix Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more t// labels Mar 2, 2026
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/kibana-management (Team:Kibana Management)

@kapral18 kapral18 changed the title fix(console): fix JSON highlighting inconsistencies for nested objects Mar 2, 2026
@kapral18 kapral18 added Feature:Console Dev Tools Console Feature Feature:Dev Tools v9.4.0 backport:version Backport to applied version labels backport:all-open Backport to all branches that could still receive a release v9.1.11 v8.19.13 v9.2.7 v9.3.2 and removed backport:version Backport to applied version labels backport:all-open Backport to all branches that could still receive a release v9.4.0 v9.2.7 v9.3.2 v9.1.11 v8.19.13 labels Mar 2, 2026
@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

Page load bundle

Size of the bundles that are downloaded on every page load. Target size is below 100kb

id before after diff
kbnUiSharedDeps-srcJs 4.7MB 4.7MB +66.0B
@kapral18 kapral18 added bug Fixes for quality problems that affect the customer experience and removed Feature:Dev Tools labels Mar 2, 2026
Copy link
Copy Markdown
Contributor

@SoniaSanzV SoniaSanzV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tested locally, lgtm!

@kapral18 kapral18 merged commit bdb1bfc into elastic:main Mar 2, 2026
55 checks passed
@kapral18 kapral18 deleted the fix/console/fix-highlighting-inconsistencies-245820 branch March 2, 2026 09:07
@kibanamachine
Copy link
Copy Markdown
Contributor

Starting backport for target branches: 8.19, 9.2, 9.3

https://github.com/elastic/kibana/actions/runs/22568942642

kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Mar 2, 2026
…lastic#255426)

Addresses elastic#245820

## Summary
- Fixes an issue in Dev Tools Console where closing nested braces
incorrectly returned the lexer to the root state, breaking syntax
highlighting for subsequent elements.

## Root Cause
- The lexer rules matched any `}` to return to the root state, which
caused it to pop out of the JSON context prematurely when encountering
nested objects.

## Fix
- Updated the rule to only return to the root state when an unindented
closing brace ends the line (`/^}\s*/`), keeping nested braces
highlighted properly without state changes.
- Added tests to cover nested objects highlighting and avoid stack limit
issues.

## Screenshots

### Before

<img width="1713" height="1083" alt="console_highlight_before"
src="https://github.com/user-attachments/assets/46ac5181-ca61-46e8-be02-fd401e4bb6ad"
/>

### After

<img width="1708" height="1084" alt="console_highlight_after"
src="https://github.com/user-attachments/assets/0ade816e-95ce-472e-b27b-31b048db4d12"
/>

## Test Plan
- Run tests: `yarn test:jest
src/platform/packages/shared/kbn-monaco/src/languages/console/lexer_rules/shared.test.ts`
- Manual verification:
  1. Open the Dev Tools Console in Kibana.
2. Paste the following request with nested JSON objects (as shown in the
screenshots):
     ```json
     PUT console_highlight_bug_test2
     {
       "mappings": {
         "properties": {
           "body": {
             "properties": {
               "properties": {
                 "properties": {
                   "structured": {
                     "type": "object",
                     "subobjects": false
                   },
                   "text": {
                     "type": "match_only_text"
                   }
                 }
               },
               "event_name": {
                 "type": "keyword"
               },
               "host": {
                 "properties": {
                   "name": {
                     "type": "alias",
                     "path": "resource.attributes.host.name"
                   }
                 }
               }
             }
           }
         }
       }
     }
     ```
3. Verify that the syntax highlighting remains consistent and doesn't
break (turn un-highlighted text/white) after the first nested closing
brace `}`. Properties like `"text"`, `"event_name"` and `"host"` should
retain their correct coloring.

## Release note
Fixes an issue in Dev Tools Console where closing nested braces broke
syntax highlighting for subsequent elements.

(cherry picked from commit bdb1bfc)
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Mar 2, 2026
…lastic#255426)

Addresses elastic#245820

## Summary
- Fixes an issue in Dev Tools Console where closing nested braces
incorrectly returned the lexer to the root state, breaking syntax
highlighting for subsequent elements.

## Root Cause
- The lexer rules matched any `}` to return to the root state, which
caused it to pop out of the JSON context prematurely when encountering
nested objects.

## Fix
- Updated the rule to only return to the root state when an unindented
closing brace ends the line (`/^}\s*/`), keeping nested braces
highlighted properly without state changes.
- Added tests to cover nested objects highlighting and avoid stack limit
issues.

## Screenshots

### Before

<img width="1713" height="1083" alt="console_highlight_before"
src="https://github.com/user-attachments/assets/46ac5181-ca61-46e8-be02-fd401e4bb6ad"
/>

### After

<img width="1708" height="1084" alt="console_highlight_after"
src="https://github.com/user-attachments/assets/0ade816e-95ce-472e-b27b-31b048db4d12"
/>

## Test Plan
- Run tests: `yarn test:jest
src/platform/packages/shared/kbn-monaco/src/languages/console/lexer_rules/shared.test.ts`
- Manual verification:
  1. Open the Dev Tools Console in Kibana.
2. Paste the following request with nested JSON objects (as shown in the
screenshots):
     ```json
     PUT console_highlight_bug_test2
     {
       "mappings": {
         "properties": {
           "body": {
             "properties": {
               "properties": {
                 "properties": {
                   "structured": {
                     "type": "object",
                     "subobjects": false
                   },
                   "text": {
                     "type": "match_only_text"
                   }
                 }
               },
               "event_name": {
                 "type": "keyword"
               },
               "host": {
                 "properties": {
                   "name": {
                     "type": "alias",
                     "path": "resource.attributes.host.name"
                   }
                 }
               }
             }
           }
         }
       }
     }
     ```
3. Verify that the syntax highlighting remains consistent and doesn't
break (turn un-highlighted text/white) after the first nested closing
brace `}`. Properties like `"text"`, `"event_name"` and `"host"` should
retain their correct coloring.

## Release note
Fixes an issue in Dev Tools Console where closing nested braces broke
syntax highlighting for subsequent elements.

(cherry picked from commit bdb1bfc)
@kibanamachine
Copy link
Copy Markdown
Contributor

💔 Some backports could not be created

Status Branch Result
8.19 Backport failed because of merge conflicts
9.2
9.3

Note: Successful backport PRs will be merged automatically after passing CI.

Manual backport

To create the backport manually run:

node scripts/backport --pr 255426

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Mar 2, 2026
…cts (#255426) (#255457)

# Backport

This will backport the following commits from `main` to `9.3`:
- [[Console] Fix JSON highlighting inconsistencies for nested objects
(#255426)](#255426)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Karen
Grigoryan","email":"karen.grigoryan@elastic.co"},"sourceCommit":{"committedDate":"2026-03-02T09:07:42Z","message":"[Console]
Fix JSON highlighting inconsistencies for nested objects
(#255426)\n\nAddresses #245820\n\n## Summary\n- Fixes an issue in Dev
Tools Console where closing nested braces\nincorrectly returned the
lexer to the root state, breaking syntax\nhighlighting for subsequent
elements.\n\n## Root Cause\n- The lexer rules matched any `}` to return
to the root state, which\ncaused it to pop out of the JSON context
prematurely when encountering\nnested objects.\n\n## Fix\n- Updated the
rule to only return to the root state when an unindented\nclosing brace
ends the line (`/^}\\s*/`), keeping nested braces\nhighlighted properly
without state changes.\n- Added tests to cover nested objects
highlighting and avoid stack limit\nissues.\n\n## Screenshots\n\n###
Before\n\n<img width=\"1713\" height=\"1083\"
alt=\"console_highlight_before\"\nsrc=\"https://github.com/user-attachments/assets/46ac5181-ca61-46e8-be02-fd401e4bb6ad\"\n/>\n
\n### After\n\n<img width=\"1708\" height=\"1084\"
alt=\"console_highlight_after\"\nsrc=\"https://github.com/user-attachments/assets/0ade816e-95ce-472e-b27b-31b048db4d12\"\n/>\n\n##
Test Plan\n- Run tests: `yarn
test:jest\nsrc/platform/packages/shared/kbn-monaco/src/languages/console/lexer_rules/shared.test.ts`\n-
Manual verification:\n 1. Open the Dev Tools Console in Kibana.\n2.
Paste the following request with nested JSON objects (as shown in
the\nscreenshots):\n ```json\n PUT console_highlight_bug_test2\n {\n
\"mappings\": {\n \"properties\": {\n \"body\": {\n \"properties\": {\n
\"properties\": {\n \"properties\": {\n \"structured\": {\n \"type\":
\"object\",\n \"subobjects\": false\n },\n \"text\": {\n \"type\":
\"match_only_text\"\n }\n }\n },\n \"event_name\": {\n \"type\":
\"keyword\"\n },\n \"host\": {\n \"properties\": {\n \"name\": {\n
\"type\": \"alias\",\n \"path\": \"resource.attributes.host.name\"\n }\n
}\n }\n }\n }\n }\n }\n }\n ```\n3. Verify that the syntax highlighting
remains consistent and doesn't\nbreak (turn un-highlighted text/white)
after the first nested closing\nbrace `}`. Properties like `\"text\"`,
`\"event_name\"` and `\"host\"` should\nretain their correct
coloring.\n\n## Release note\nFixes an issue in Dev Tools Console where
closing nested braces broke\nsyntax highlighting for subsequent
elements.","sha":"bdb1bfc5c2042a9ac9dda4814f0d874d3d8ee214","branchLabelMapping":{"^v9.4.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Feature:Console","release_note:fix","Team:Kibana
Management","backport:all-open","v9.4.0"],"title":"[Console] Fix JSON
highlighting inconsistencies for nested
objects","number":255426,"url":"https://github.com/elastic/kibana/pull/255426","mergeCommit":{"message":"[Console]
Fix JSON highlighting inconsistencies for nested objects
(#255426)\n\nAddresses #245820\n\n## Summary\n- Fixes an issue in Dev
Tools Console where closing nested braces\nincorrectly returned the
lexer to the root state, breaking syntax\nhighlighting for subsequent
elements.\n\n## Root Cause\n- The lexer rules matched any `}` to return
to the root state, which\ncaused it to pop out of the JSON context
prematurely when encountering\nnested objects.\n\n## Fix\n- Updated the
rule to only return to the root state when an unindented\nclosing brace
ends the line (`/^}\\s*/`), keeping nested braces\nhighlighted properly
without state changes.\n- Added tests to cover nested objects
highlighting and avoid stack limit\nissues.\n\n## Screenshots\n\n###
Before\n\n<img width=\"1713\" height=\"1083\"
alt=\"console_highlight_before\"\nsrc=\"https://github.com/user-attachments/assets/46ac5181-ca61-46e8-be02-fd401e4bb6ad\"\n/>\n
\n### After\n\n<img width=\"1708\" height=\"1084\"
alt=\"console_highlight_after\"\nsrc=\"https://github.com/user-attachments/assets/0ade816e-95ce-472e-b27b-31b048db4d12\"\n/>\n\n##
Test Plan\n- Run tests: `yarn
test:jest\nsrc/platform/packages/shared/kbn-monaco/src/languages/console/lexer_rules/shared.test.ts`\n-
Manual verification:\n 1. Open the Dev Tools Console in Kibana.\n2.
Paste the following request with nested JSON objects (as shown in
the\nscreenshots):\n ```json\n PUT console_highlight_bug_test2\n {\n
\"mappings\": {\n \"properties\": {\n \"body\": {\n \"properties\": {\n
\"properties\": {\n \"properties\": {\n \"structured\": {\n \"type\":
\"object\",\n \"subobjects\": false\n },\n \"text\": {\n \"type\":
\"match_only_text\"\n }\n }\n },\n \"event_name\": {\n \"type\":
\"keyword\"\n },\n \"host\": {\n \"properties\": {\n \"name\": {\n
\"type\": \"alias\",\n \"path\": \"resource.attributes.host.name\"\n }\n
}\n }\n }\n }\n }\n }\n }\n ```\n3. Verify that the syntax highlighting
remains consistent and doesn't\nbreak (turn un-highlighted text/white)
after the first nested closing\nbrace `}`. Properties like `\"text\"`,
`\"event_name\"` and `\"host\"` should\nretain their correct
coloring.\n\n## Release note\nFixes an issue in Dev Tools Console where
closing nested braces broke\nsyntax highlighting for subsequent
elements.","sha":"bdb1bfc5c2042a9ac9dda4814f0d874d3d8ee214"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.4.0","branchLabelMappingKey":"^v9.4.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/255426","number":255426,"mergeCommit":{"message":"[Console]
Fix JSON highlighting inconsistencies for nested objects
(#255426)\n\nAddresses #245820\n\n## Summary\n- Fixes an issue in Dev
Tools Console where closing nested braces\nincorrectly returned the
lexer to the root state, breaking syntax\nhighlighting for subsequent
elements.\n\n## Root Cause\n- The lexer rules matched any `}` to return
to the root state, which\ncaused it to pop out of the JSON context
prematurely when encountering\nnested objects.\n\n## Fix\n- Updated the
rule to only return to the root state when an unindented\nclosing brace
ends the line (`/^}\\s*/`), keeping nested braces\nhighlighted properly
without state changes.\n- Added tests to cover nested objects
highlighting and avoid stack limit\nissues.\n\n## Screenshots\n\n###
Before\n\n<img width=\"1713\" height=\"1083\"
alt=\"console_highlight_before\"\nsrc=\"https://github.com/user-attachments/assets/46ac5181-ca61-46e8-be02-fd401e4bb6ad\"\n/>\n
\n### After\n\n<img width=\"1708\" height=\"1084\"
alt=\"console_highlight_after\"\nsrc=\"https://github.com/user-attachments/assets/0ade816e-95ce-472e-b27b-31b048db4d12\"\n/>\n\n##
Test Plan\n- Run tests: `yarn
test:jest\nsrc/platform/packages/shared/kbn-monaco/src/languages/console/lexer_rules/shared.test.ts`\n-
Manual verification:\n 1. Open the Dev Tools Console in Kibana.\n2.
Paste the following request with nested JSON objects (as shown in
the\nscreenshots):\n ```json\n PUT console_highlight_bug_test2\n {\n
\"mappings\": {\n \"properties\": {\n \"body\": {\n \"properties\": {\n
\"properties\": {\n \"properties\": {\n \"structured\": {\n \"type\":
\"object\",\n \"subobjects\": false\n },\n \"text\": {\n \"type\":
\"match_only_text\"\n }\n }\n },\n \"event_name\": {\n \"type\":
\"keyword\"\n },\n \"host\": {\n \"properties\": {\n \"name\": {\n
\"type\": \"alias\",\n \"path\": \"resource.attributes.host.name\"\n }\n
}\n }\n }\n }\n }\n }\n }\n ```\n3. Verify that the syntax highlighting
remains consistent and doesn't\nbreak (turn un-highlighted text/white)
after the first nested closing\nbrace `}`. Properties like `\"text\"`,
`\"event_name\"` and `\"host\"` should\nretain their correct
coloring.\n\n## Release note\nFixes an issue in Dev Tools Console where
closing nested braces broke\nsyntax highlighting for subsequent
elements.","sha":"bdb1bfc5c2042a9ac9dda4814f0d874d3d8ee214"}}]}]
BACKPORT-->

Co-authored-by: Karen Grigoryan <karen.grigoryan@elastic.co>
mbondyra pushed a commit to mbondyra/kibana that referenced this pull request Mar 2, 2026
…lastic#255426)

Addresses elastic#245820

## Summary
- Fixes an issue in Dev Tools Console where closing nested braces
incorrectly returned the lexer to the root state, breaking syntax
highlighting for subsequent elements.

## Root Cause
- The lexer rules matched any `}` to return to the root state, which
caused it to pop out of the JSON context prematurely when encountering
nested objects.

## Fix
- Updated the rule to only return to the root state when an unindented
closing brace ends the line (`/^}\s*/`), keeping nested braces
highlighted properly without state changes.
- Added tests to cover nested objects highlighting and avoid stack limit
issues.

## Screenshots

### Before

<img width="1713" height="1083" alt="console_highlight_before"
src="https://github.com/user-attachments/assets/46ac5181-ca61-46e8-be02-fd401e4bb6ad"
/>
 
### After

<img width="1708" height="1084" alt="console_highlight_after"
src="https://github.com/user-attachments/assets/0ade816e-95ce-472e-b27b-31b048db4d12"
/>

## Test Plan
- Run tests: `yarn test:jest
src/platform/packages/shared/kbn-monaco/src/languages/console/lexer_rules/shared.test.ts`
- Manual verification:
  1. Open the Dev Tools Console in Kibana.
2. Paste the following request with nested JSON objects (as shown in the
screenshots):
     ```json
     PUT console_highlight_bug_test2
     {
       "mappings": {
         "properties": {
           "body": {
             "properties": {
               "properties": {
                 "properties": {
                   "structured": {
                     "type": "object",
                     "subobjects": false
                   },
                   "text": {
                     "type": "match_only_text"
                   }
                 }
               },
               "event_name": {
                 "type": "keyword"
               },
               "host": {
                 "properties": {
                   "name": {
                     "type": "alias",
                     "path": "resource.attributes.host.name"
                   }
                 }
               }
             }
           }
         }
       }
     }
     ```
3. Verify that the syntax highlighting remains consistent and doesn't
break (turn un-highlighted text/white) after the first nested closing
brace `}`. Properties like `"text"`, `"event_name"` and `"host"` should
retain their correct coloring.

## Release note
Fixes an issue in Dev Tools Console where closing nested braces broke
syntax highlighting for subsequent elements.
kibanamachine added a commit that referenced this pull request Mar 2, 2026
…cts (#255426) (#255456)

# Backport

This will backport the following commits from `main` to `9.2`:
- [[Console] Fix JSON highlighting inconsistencies for nested objects
(#255426)](#255426)

<!--- Backport version: 9.6.6 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Karen
Grigoryan","email":"karen.grigoryan@elastic.co"},"sourceCommit":{"committedDate":"2026-03-02T09:07:42Z","message":"[Console]
Fix JSON highlighting inconsistencies for nested objects
(#255426)\n\nAddresses #245820\n\n## Summary\n- Fixes an issue in Dev
Tools Console where closing nested braces\nincorrectly returned the
lexer to the root state, breaking syntax\nhighlighting for subsequent
elements.\n\n## Root Cause\n- The lexer rules matched any `}` to return
to the root state, which\ncaused it to pop out of the JSON context
prematurely when encountering\nnested objects.\n\n## Fix\n- Updated the
rule to only return to the root state when an unindented\nclosing brace
ends the line (`/^}\\s*/`), keeping nested braces\nhighlighted properly
without state changes.\n- Added tests to cover nested objects
highlighting and avoid stack limit\nissues.\n\n## Screenshots\n\n###
Before\n\n<img width=\"1713\" height=\"1083\"
alt=\"console_highlight_before\"\nsrc=\"https://github.com/user-attachments/assets/46ac5181-ca61-46e8-be02-fd401e4bb6ad\"\n/>\n
\n### After\n\n<img width=\"1708\" height=\"1084\"
alt=\"console_highlight_after\"\nsrc=\"https://github.com/user-attachments/assets/0ade816e-95ce-472e-b27b-31b048db4d12\"\n/>\n\n##
Test Plan\n- Run tests: `yarn
test:jest\nsrc/platform/packages/shared/kbn-monaco/src/languages/console/lexer_rules/shared.test.ts`\n-
Manual verification:\n 1. Open the Dev Tools Console in Kibana.\n2.
Paste the following request with nested JSON objects (as shown in
the\nscreenshots):\n ```json\n PUT console_highlight_bug_test2\n {\n
\"mappings\": {\n \"properties\": {\n \"body\": {\n \"properties\": {\n
\"properties\": {\n \"properties\": {\n \"structured\": {\n \"type\":
\"object\",\n \"subobjects\": false\n },\n \"text\": {\n \"type\":
\"match_only_text\"\n }\n }\n },\n \"event_name\": {\n \"type\":
\"keyword\"\n },\n \"host\": {\n \"properties\": {\n \"name\": {\n
\"type\": \"alias\",\n \"path\": \"resource.attributes.host.name\"\n }\n
}\n }\n }\n }\n }\n }\n }\n ```\n3. Verify that the syntax highlighting
remains consistent and doesn't\nbreak (turn un-highlighted text/white)
after the first nested closing\nbrace `}`. Properties like `\"text\"`,
`\"event_name\"` and `\"host\"` should\nretain their correct
coloring.\n\n## Release note\nFixes an issue in Dev Tools Console where
closing nested braces broke\nsyntax highlighting for subsequent
elements.","sha":"bdb1bfc5c2042a9ac9dda4814f0d874d3d8ee214","branchLabelMapping":{"^v9.4.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Feature:Console","release_note:fix","Team:Kibana
Management","backport:all-open","v9.4.0"],"title":"[Console] Fix JSON
highlighting inconsistencies for nested
objects","number":255426,"url":"https://github.com/elastic/kibana/pull/255426","mergeCommit":{"message":"[Console]
Fix JSON highlighting inconsistencies for nested objects
(#255426)\n\nAddresses #245820\n\n## Summary\n- Fixes an issue in Dev
Tools Console where closing nested braces\nincorrectly returned the
lexer to the root state, breaking syntax\nhighlighting for subsequent
elements.\n\n## Root Cause\n- The lexer rules matched any `}` to return
to the root state, which\ncaused it to pop out of the JSON context
prematurely when encountering\nnested objects.\n\n## Fix\n- Updated the
rule to only return to the root state when an unindented\nclosing brace
ends the line (`/^}\\s*/`), keeping nested braces\nhighlighted properly
without state changes.\n- Added tests to cover nested objects
highlighting and avoid stack limit\nissues.\n\n## Screenshots\n\n###
Before\n\n<img width=\"1713\" height=\"1083\"
alt=\"console_highlight_before\"\nsrc=\"https://github.com/user-attachments/assets/46ac5181-ca61-46e8-be02-fd401e4bb6ad\"\n/>\n
\n### After\n\n<img width=\"1708\" height=\"1084\"
alt=\"console_highlight_after\"\nsrc=\"https://github.com/user-attachments/assets/0ade816e-95ce-472e-b27b-31b048db4d12\"\n/>\n\n##
Test Plan\n- Run tests: `yarn
test:jest\nsrc/platform/packages/shared/kbn-monaco/src/languages/console/lexer_rules/shared.test.ts`\n-
Manual verification:\n 1. Open the Dev Tools Console in Kibana.\n2.
Paste the following request with nested JSON objects (as shown in
the\nscreenshots):\n ```json\n PUT console_highlight_bug_test2\n {\n
\"mappings\": {\n \"properties\": {\n \"body\": {\n \"properties\": {\n
\"properties\": {\n \"properties\": {\n \"structured\": {\n \"type\":
\"object\",\n \"subobjects\": false\n },\n \"text\": {\n \"type\":
\"match_only_text\"\n }\n }\n },\n \"event_name\": {\n \"type\":
\"keyword\"\n },\n \"host\": {\n \"properties\": {\n \"name\": {\n
\"type\": \"alias\",\n \"path\": \"resource.attributes.host.name\"\n }\n
}\n }\n }\n }\n }\n }\n }\n ```\n3. Verify that the syntax highlighting
remains consistent and doesn't\nbreak (turn un-highlighted text/white)
after the first nested closing\nbrace `}`. Properties like `\"text\"`,
`\"event_name\"` and `\"host\"` should\nretain their correct
coloring.\n\n## Release note\nFixes an issue in Dev Tools Console where
closing nested braces broke\nsyntax highlighting for subsequent
elements.","sha":"bdb1bfc5c2042a9ac9dda4814f0d874d3d8ee214"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.4.0","branchLabelMappingKey":"^v9.4.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/255426","number":255426,"mergeCommit":{"message":"[Console]
Fix JSON highlighting inconsistencies for nested objects
(#255426)\n\nAddresses #245820\n\n## Summary\n- Fixes an issue in Dev
Tools Console where closing nested braces\nincorrectly returned the
lexer to the root state, breaking syntax\nhighlighting for subsequent
elements.\n\n## Root Cause\n- The lexer rules matched any `}` to return
to the root state, which\ncaused it to pop out of the JSON context
prematurely when encountering\nnested objects.\n\n## Fix\n- Updated the
rule to only return to the root state when an unindented\nclosing brace
ends the line (`/^}\\s*/`), keeping nested braces\nhighlighted properly
without state changes.\n- Added tests to cover nested objects
highlighting and avoid stack limit\nissues.\n\n## Screenshots\n\n###
Before\n\n<img width=\"1713\" height=\"1083\"
alt=\"console_highlight_before\"\nsrc=\"https://github.com/user-attachments/assets/46ac5181-ca61-46e8-be02-fd401e4bb6ad\"\n/>\n
\n### After\n\n<img width=\"1708\" height=\"1084\"
alt=\"console_highlight_after\"\nsrc=\"https://github.com/user-attachments/assets/0ade816e-95ce-472e-b27b-31b048db4d12\"\n/>\n\n##
Test Plan\n- Run tests: `yarn
test:jest\nsrc/platform/packages/shared/kbn-monaco/src/languages/console/lexer_rules/shared.test.ts`\n-
Manual verification:\n 1. Open the Dev Tools Console in Kibana.\n2.
Paste the following request with nested JSON objects (as shown in
the\nscreenshots):\n ```json\n PUT console_highlight_bug_test2\n {\n
\"mappings\": {\n \"properties\": {\n \"body\": {\n \"properties\": {\n
\"properties\": {\n \"properties\": {\n \"structured\": {\n \"type\":
\"object\",\n \"subobjects\": false\n },\n \"text\": {\n \"type\":
\"match_only_text\"\n }\n }\n },\n \"event_name\": {\n \"type\":
\"keyword\"\n },\n \"host\": {\n \"properties\": {\n \"name\": {\n
\"type\": \"alias\",\n \"path\": \"resource.attributes.host.name\"\n }\n
}\n }\n }\n }\n }\n }\n }\n ```\n3. Verify that the syntax highlighting
remains consistent and doesn't\nbreak (turn un-highlighted text/white)
after the first nested closing\nbrace `}`. Properties like `\"text\"`,
`\"event_name\"` and `\"host\"` should\nretain their correct
coloring.\n\n## Release note\nFixes an issue in Dev Tools Console where
closing nested braces broke\nsyntax highlighting for subsequent
elements.","sha":"bdb1bfc5c2042a9ac9dda4814f0d874d3d8ee214"}}]}]
BACKPORT-->

Co-authored-by: Karen Grigoryan <karen.grigoryan@elastic.co>
kapral18 added a commit to kapral18/kibana that referenced this pull request Mar 2, 2026
…lastic#255426)

Addresses elastic#245820

## Summary
- Fixes an issue in Dev Tools Console where closing nested braces
incorrectly returned the lexer to the root state, breaking syntax
highlighting for subsequent elements.

## Root Cause
- The lexer rules matched any `}` to return to the root state, which
caused it to pop out of the JSON context prematurely when encountering
nested objects.

## Fix
- Updated the rule to only return to the root state when an unindented
closing brace ends the line (`/^}\s*/`), keeping nested braces
highlighted properly without state changes.
- Added tests to cover nested objects highlighting and avoid stack limit
issues.

## Screenshots

### Before

<img width="1713" height="1083" alt="console_highlight_before"
src="https://github.com/user-attachments/assets/46ac5181-ca61-46e8-be02-fd401e4bb6ad"
/>

### After

<img width="1708" height="1084" alt="console_highlight_after"
src="https://github.com/user-attachments/assets/0ade816e-95ce-472e-b27b-31b048db4d12"
/>

## Test Plan
- Run tests: `yarn test:jest
src/platform/packages/shared/kbn-monaco/src/languages/console/lexer_rules/shared.test.ts`
- Manual verification:
  1. Open the Dev Tools Console in Kibana.
2. Paste the following request with nested JSON objects (as shown in the
screenshots):
     ```json
     PUT console_highlight_bug_test2
     {
       "mappings": {
         "properties": {
           "body": {
             "properties": {
               "properties": {
                 "properties": {
                   "structured": {
                     "type": "object",
                     "subobjects": false
                   },
                   "text": {
                     "type": "match_only_text"
                   }
                 }
               },
               "event_name": {
                 "type": "keyword"
               },
               "host": {
                 "properties": {
                   "name": {
                     "type": "alias",
                     "path": "resource.attributes.host.name"
                   }
                 }
               }
             }
           }
         }
       }
     }
     ```
3. Verify that the syntax highlighting remains consistent and doesn't
break (turn un-highlighted text/white) after the first nested closing
brace `}`. Properties like `"text"`, `"event_name"` and `"host"` should
retain their correct coloring.

## Release note
Fixes an issue in Dev Tools Console where closing nested braces broke
syntax highlighting for subsequent elements.

(cherry picked from commit bdb1bfc)

# Conflicts:
#	src/platform/packages/shared/kbn-monaco/src/console/lexer_rules/shared.test.ts
@kapral18
Copy link
Copy Markdown
Contributor Author

kapral18 commented Mar 2, 2026

💚 All backports created successfully

Status Branch Result
8.19

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Mar 4, 2026
@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync.
cc: @kapral18

1 similar comment
@kibanamachine
Copy link
Copy Markdown
Contributor

Looks like this PR has backport PRs but they still haven't been merged. Please merge them ASAP to keep the branches relatively in sync.
cc: @kapral18

kapral18 added a commit that referenced this pull request Mar 6, 2026
…ects (#255426) (#255516)

# Backport

This will backport the following commits from `main` to `8.19`:
- [[Console] Fix JSON highlighting inconsistencies for nested objects
(#255426)](#255426)

<!--- Backport version: 10.2.0 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)

<!--BACKPORT [{"author":{"name":"Karen
Grigoryan","email":"karen.grigoryan@elastic.co"},"sourceCommit":{"committedDate":"2026-03-02T09:07:42Z","message":"[Console]
Fix JSON highlighting inconsistencies for nested objects
(#255426)\n\nAddresses #245820\n\n## Summary\n- Fixes an issue in Dev
Tools Console where closing nested braces\nincorrectly returned the
lexer to the root state, breaking syntax\nhighlighting for subsequent
elements.\n\n## Root Cause\n- The lexer rules matched any `}` to return
to the root state, which\ncaused it to pop out of the JSON context
prematurely when encountering\nnested objects.\n\n## Fix\n- Updated the
rule to only return to the root state when an unindented\nclosing brace
ends the line (`/^}\\s*/`), keeping nested braces\nhighlighted properly
without state changes.\n- Added tests to cover nested objects
highlighting and avoid stack limit\nissues.\n\n## Screenshots\n\n###
Before\n\n<img width=\"1713\" height=\"1083\"
alt=\"console_highlight_before\"\nsrc=\"https://github.com/user-attachments/assets/46ac5181-ca61-46e8-be02-fd401e4bb6ad\"\n/>\n
\n### After\n\n<img width=\"1708\" height=\"1084\"
alt=\"console_highlight_after\"\nsrc=\"https://github.com/user-attachments/assets/0ade816e-95ce-472e-b27b-31b048db4d12\"\n/>\n\n##
Test Plan\n- Run tests: `yarn
test:jest\nsrc/platform/packages/shared/kbn-monaco/src/languages/console/lexer_rules/shared.test.ts`\n-
Manual verification:\n 1. Open the Dev Tools Console in Kibana.\n2.
Paste the following request with nested JSON objects (as shown in
the\nscreenshots):\n ```json\n PUT console_highlight_bug_test2\n {\n
\"mappings\": {\n \"properties\": {\n \"body\": {\n \"properties\": {\n
\"properties\": {\n \"properties\": {\n \"structured\": {\n \"type\":
\"object\",\n \"subobjects\": false\n },\n \"text\": {\n \"type\":
\"match_only_text\"\n }\n }\n },\n \"event_name\": {\n \"type\":
\"keyword\"\n },\n \"host\": {\n \"properties\": {\n \"name\": {\n
\"type\": \"alias\",\n \"path\": \"resource.attributes.host.name\"\n }\n
}\n }\n }\n }\n }\n }\n }\n ```\n3. Verify that the syntax highlighting
remains consistent and doesn't\nbreak (turn un-highlighted text/white)
after the first nested closing\nbrace `}`. Properties like `\"text\"`,
`\"event_name\"` and `\"host\"` should\nretain their correct
coloring.\n\n## Release note\nFixes an issue in Dev Tools Console where
closing nested braces broke\nsyntax highlighting for subsequent
elements.","sha":"bdb1bfc5c2042a9ac9dda4814f0d874d3d8ee214","branchLabelMapping":{"^v9.4.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Feature:Console","release_note:fix","Team:Kibana
Management","backport:all-open","v9.4.0","v9.2.7","v9.3.2"],"title":"[Console]
Fix JSON highlighting inconsistencies for nested
objects","number":255426,"url":"https://github.com/elastic/kibana/pull/255426","mergeCommit":{"message":"[Console]
Fix JSON highlighting inconsistencies for nested objects
(#255426)\n\nAddresses #245820\n\n## Summary\n- Fixes an issue in Dev
Tools Console where closing nested braces\nincorrectly returned the
lexer to the root state, breaking syntax\nhighlighting for subsequent
elements.\n\n## Root Cause\n- The lexer rules matched any `}` to return
to the root state, which\ncaused it to pop out of the JSON context
prematurely when encountering\nnested objects.\n\n## Fix\n- Updated the
rule to only return to the root state when an unindented\nclosing brace
ends the line (`/^}\\s*/`), keeping nested braces\nhighlighted properly
without state changes.\n- Added tests to cover nested objects
highlighting and avoid stack limit\nissues.\n\n## Screenshots\n\n###
Before\n\n<img width=\"1713\" height=\"1083\"
alt=\"console_highlight_before\"\nsrc=\"https://github.com/user-attachments/assets/46ac5181-ca61-46e8-be02-fd401e4bb6ad\"\n/>\n
\n### After\n\n<img width=\"1708\" height=\"1084\"
alt=\"console_highlight_after\"\nsrc=\"https://github.com/user-attachments/assets/0ade816e-95ce-472e-b27b-31b048db4d12\"\n/>\n\n##
Test Plan\n- Run tests: `yarn
test:jest\nsrc/platform/packages/shared/kbn-monaco/src/languages/console/lexer_rules/shared.test.ts`\n-
Manual verification:\n 1. Open the Dev Tools Console in Kibana.\n2.
Paste the following request with nested JSON objects (as shown in
the\nscreenshots):\n ```json\n PUT console_highlight_bug_test2\n {\n
\"mappings\": {\n \"properties\": {\n \"body\": {\n \"properties\": {\n
\"properties\": {\n \"properties\": {\n \"structured\": {\n \"type\":
\"object\",\n \"subobjects\": false\n },\n \"text\": {\n \"type\":
\"match_only_text\"\n }\n }\n },\n \"event_name\": {\n \"type\":
\"keyword\"\n },\n \"host\": {\n \"properties\": {\n \"name\": {\n
\"type\": \"alias\",\n \"path\": \"resource.attributes.host.name\"\n }\n
}\n }\n }\n }\n }\n }\n }\n ```\n3. Verify that the syntax highlighting
remains consistent and doesn't\nbreak (turn un-highlighted text/white)
after the first nested closing\nbrace `}`. Properties like `\"text\"`,
`\"event_name\"` and `\"host\"` should\nretain their correct
coloring.\n\n## Release note\nFixes an issue in Dev Tools Console where
closing nested braces broke\nsyntax highlighting for subsequent
elements.","sha":"bdb1bfc5c2042a9ac9dda4814f0d874d3d8ee214"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.4.0","branchLabelMappingKey":"^v9.4.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/255426","number":255426,"mergeCommit":{"message":"[Console]
Fix JSON highlighting inconsistencies for nested objects
(#255426)\n\nAddresses #245820\n\n## Summary\n- Fixes an issue in Dev
Tools Console where closing nested braces\nincorrectly returned the
lexer to the root state, breaking syntax\nhighlighting for subsequent
elements.\n\n## Root Cause\n- The lexer rules matched any `}` to return
to the root state, which\ncaused it to pop out of the JSON context
prematurely when encountering\nnested objects.\n\n## Fix\n- Updated the
rule to only return to the root state when an unindented\nclosing brace
ends the line (`/^}\\s*/`), keeping nested braces\nhighlighted properly
without state changes.\n- Added tests to cover nested objects
highlighting and avoid stack limit\nissues.\n\n## Screenshots\n\n###
Before\n\n<img width=\"1713\" height=\"1083\"
alt=\"console_highlight_before\"\nsrc=\"https://github.com/user-attachments/assets/46ac5181-ca61-46e8-be02-fd401e4bb6ad\"\n/>\n
\n### After\n\n<img width=\"1708\" height=\"1084\"
alt=\"console_highlight_after\"\nsrc=\"https://github.com/user-attachments/assets/0ade816e-95ce-472e-b27b-31b048db4d12\"\n/>\n\n##
Test Plan\n- Run tests: `yarn
test:jest\nsrc/platform/packages/shared/kbn-monaco/src/languages/console/lexer_rules/shared.test.ts`\n-
Manual verification:\n 1. Open the Dev Tools Console in Kibana.\n2.
Paste the following request with nested JSON objects (as shown in
the\nscreenshots):\n ```json\n PUT console_highlight_bug_test2\n {\n
\"mappings\": {\n \"properties\": {\n \"body\": {\n \"properties\": {\n
\"properties\": {\n \"properties\": {\n \"structured\": {\n \"type\":
\"object\",\n \"subobjects\": false\n },\n \"text\": {\n \"type\":
\"match_only_text\"\n }\n }\n },\n \"event_name\": {\n \"type\":
\"keyword\"\n },\n \"host\": {\n \"properties\": {\n \"name\": {\n
\"type\": \"alias\",\n \"path\": \"resource.attributes.host.name\"\n }\n
}\n }\n }\n }\n }\n }\n }\n ```\n3. Verify that the syntax highlighting
remains consistent and doesn't\nbreak (turn un-highlighted text/white)
after the first nested closing\nbrace `}`. Properties like `\"text\"`,
`\"event_name\"` and `\"host\"` should\nretain their correct
coloring.\n\n## Release note\nFixes an issue in Dev Tools Console where
closing nested braces broke\nsyntax highlighting for subsequent
elements.","sha":"bdb1bfc5c2042a9ac9dda4814f0d874d3d8ee214"}},{"branch":"9.2","label":"v9.2.7","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/255456","number":255456,"state":"MERGED","mergeCommit":{"sha":"9f18f5067056ac42735c958276a656a799be8044","message":"[9.2]
[Console] Fix JSON highlighting inconsistencies for nested objects
(#255426) (#255456)\n\n# Backport\n\nThis will backport the following
commits from `main` to `9.2`:\n- [[Console] Fix JSON highlighting
inconsistencies for nested
objects\n(#255426)](https://github.com/elastic/kibana/pull/255426)\n\n\n\n###
Questions ?\nPlease refer to the [Backport
tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n\n\nCo-authored-by:
Karen Grigoryan
<karen.grigoryan@elastic.co>"}},{"branch":"9.3","label":"v9.3.2","branchLabelMappingKey":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"url":"https://github.com/elastic/kibana/pull/255457","number":255457,"state":"MERGED","mergeCommit":{"sha":"873dbdb15ded3fc14b0be04281e48fa724c05382","message":"[9.3]
[Console] Fix JSON highlighting inconsistencies for nested objects
(#255426) (#255457)\n\n# Backport\n\nThis will backport the following
commits from `main` to `9.3`:\n- [[Console] Fix JSON highlighting
inconsistencies for nested
objects\n(#255426)](https://github.com/elastic/kibana/pull/255426)\n\n\n\n###
Questions ?\nPlease refer to the [Backport
tool\ndocumentation](https://github.com/sorenlouv/backport)\n\n\n\nCo-authored-by:
Karen Grigoryan <karen.grigoryan@elastic.co>"}}]}] BACKPORT-->
@kibanamachine kibanamachine added v8.19.13 and removed backport missing Added to PRs automatically when the are determined to be missing a backport. labels Mar 6, 2026
qn895 pushed a commit to qn895/kibana that referenced this pull request Mar 11, 2026
…lastic#255426)

Addresses elastic#245820

## Summary
- Fixes an issue in Dev Tools Console where closing nested braces
incorrectly returned the lexer to the root state, breaking syntax
highlighting for subsequent elements.

## Root Cause
- The lexer rules matched any `}` to return to the root state, which
caused it to pop out of the JSON context prematurely when encountering
nested objects.

## Fix
- Updated the rule to only return to the root state when an unindented
closing brace ends the line (`/^}\s*/`), keeping nested braces
highlighted properly without state changes.
- Added tests to cover nested objects highlighting and avoid stack limit
issues.

## Screenshots

### Before

<img width="1713" height="1083" alt="console_highlight_before"
src="https://github.com/user-attachments/assets/46ac5181-ca61-46e8-be02-fd401e4bb6ad"
/>
 
### After

<img width="1708" height="1084" alt="console_highlight_after"
src="https://github.com/user-attachments/assets/0ade816e-95ce-472e-b27b-31b048db4d12"
/>

## Test Plan
- Run tests: `yarn test:jest
src/platform/packages/shared/kbn-monaco/src/languages/console/lexer_rules/shared.test.ts`
- Manual verification:
  1. Open the Dev Tools Console in Kibana.
2. Paste the following request with nested JSON objects (as shown in the
screenshots):
     ```json
     PUT console_highlight_bug_test2
     {
       "mappings": {
         "properties": {
           "body": {
             "properties": {
               "properties": {
                 "properties": {
                   "structured": {
                     "type": "object",
                     "subobjects": false
                   },
                   "text": {
                     "type": "match_only_text"
                   }
                 }
               },
               "event_name": {
                 "type": "keyword"
               },
               "host": {
                 "properties": {
                   "name": {
                     "type": "alias",
                     "path": "resource.attributes.host.name"
                   }
                 }
               }
             }
           }
         }
       }
     }
     ```
3. Verify that the syntax highlighting remains consistent and doesn't
break (turn un-highlighted text/white) after the first nested closing
brace `}`. Properties like `"text"`, `"event_name"` and `"host"` should
retain their correct coloring.

## Release note
Fixes an issue in Dev Tools Console where closing nested braces broke
syntax highlighting for subsequent elements.
kapral18 added a commit to kapral18/kibana that referenced this pull request Mar 13, 2026
Closes elastic#256864

## Summary

Fixes a regression introduced in elastic#255426 where subsequent HTTP requests lose their highlighting if the preceding request body contains deeply nested objects with closing braces on their own lines.

### The Problem

Because of a previous stack overflow bug (elastic#238531), Console's JSON lexer cannot use Monarch's `@push` and `@pop` states to track brace nesting depth. The state machine is flat.

In elastic#255426, we tried to heuristic-guess the end of a JSON body by returning to the `root` state when encountering a `}` at the end of a line. However, this heuristic fails on deeply nested JSON where intermediate closing braces (like `}`) appear on their own lines. This caused the lexer to prematurely exit `json_root` and fall back to plain `text` tokenization for the rest of the body and subsequent requests.

### The Fix

Instead of trying to guess when the JSON body ends using fragile regex heuristics, we use a more robust "resynchronization" pattern:

1. **`shared.ts` (JSON parser):** Removed the `}` -> `root` transition entirely. The lexer now stays safely inside `json_root` regardless of indentation or nesting.
2. **`console_editor.ts` (HTTP wrapper):** Injected the HTTP method recognition rules (`GET`, `POST`, `PUT`, etc.) directly into the `json_root` state.

Now, the lexer stays in `json_root` (preserving all rich JSON highlighting) until it sees undeniable proof of a new request (an HTTP method or a `#!` warning comment) at the start of a line, at which point it breaks out and starts parsing the new request.

### Testing

- Added unit tests to `shared.test.ts` to verify that intermediate closing braces do not break highlighting.
- Added unit tests to verify that indented top-level closing braces correctly transition to the next request.
- Verified manually using Playwright that deeply nested JSON (like `aggregations` and `_meta`) retains its highlighting.
- Verified that all previous fixes (elastic#255426, elastic#255649, elastic#256286) remain intact.

Made-with: Cursor
kapral18 added a commit to kapral18/kibana that referenced this pull request Mar 13, 2026
Closes elastic#256864

## Summary

Fixes a regression introduced in elastic#255426 where subsequent HTTP requests lose their highlighting if the preceding request body contains deeply nested objects with closing braces on their own lines.

### The Problem

Because of a previous stack overflow bug (elastic#238531), Console's JSON lexer cannot use Monarch's `@push` and `@pop` states to track brace nesting depth. The state machine is flat.

In elastic#255426, we tried to heuristic-guess the end of a JSON body by returning to the `root` state when encountering a `}` at the end of a line. However, this heuristic fails on deeply nested JSON where intermediate closing braces (like `}`) appear on their own lines. This caused the lexer to prematurely exit `json_root` and fall back to plain `text` tokenization for the rest of the body and subsequent requests.

### The Fix

Instead of trying to guess when the JSON body ends using fragile regex heuristics, we use a more robust "resynchronization" pattern:

1. **`shared.ts` (JSON parser):** Removed the `}` -> `root` transition entirely. The lexer now stays safely inside `json_root` regardless of indentation or nesting.
2. **`console_editor.ts` (HTTP wrapper):** Injected the HTTP method recognition rules (`GET`, `POST`, `PUT`, etc.) directly into the `json_root` state.

Now, the lexer stays in `json_root` (preserving all rich JSON highlighting) until it sees undeniable proof of a new request (an HTTP method or a `#!` warning comment) at the start of a line, at which point it breaks out and starts parsing the new request.

### Testing

- Added unit tests to `shared.test.ts` to verify that intermediate closing braces do not break highlighting.
- Added unit tests to verify that indented top-level closing braces correctly transition to the next request.
- Verified manually using Playwright that deeply nested JSON (like `aggregations` and `_meta`) retains its highlighting.
- Verified that all previous fixes (elastic#255426, elastic#255649, elastic#256286) remain intact.

Made-with: Cursor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:all-open Backport to all branches that could still receive a release bug Fixes for quality problems that affect the customer experience Feature:Console Dev Tools Console Feature release_note:fix Team:Kibana Management Dev Tools, Index Management, Upgrade Assistant, ILM, Ingest Node Pipelines, and more t// v8.19.13 v9.2.7 v9.3.2 v9.4.0

4 participants