[Console] Fix JSON highlighting inconsistencies for nested objects#255426
Conversation
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
|
Pinging @elastic/kibana-management (Team:Kibana Management) |
💚 Build Succeeded
Metrics [docs]Page load bundle
|
SoniaSanzV
left a comment
There was a problem hiding this comment.
tested locally, lgtm!
|
Starting backport for target branches: 8.19, 9.2, 9.3 |
…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)
…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)
💔 Some backports could not be created
Note: Successful backport PRs will be merged automatically after passing CI. Manual backportTo create the backport manually run: Questions ?Please refer to the Backport tool documentation |
…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>
…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.
…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>
…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
💚 All backports created successfully
Note: Successful backport PRs will be merged automatically after passing CI. Questions ?Please refer to the Backport tool documentation |
|
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. |
1 similar comment
|
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. |
…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-->
…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.
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
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
Addresses #245820
Summary
Root Cause
}to return to the root state, which caused it to pop out of the JSON context prematurely when encountering nested objects.Fix
/^}\s*/), keeping nested braces highlighted properly without state changes.Screenshots
Before
After
Test Plan
yarn test:jest src/platform/packages/shared/kbn-monaco/src/languages/console/lexer_rules/shared.test.ts}. 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.