From ab6bd1bc33b66d55e79ceb9046f9a5ed3beb0076 Mon Sep 17 00:00:00 2001 From: Abhilash-Puthukkudi Date: Sun, 29 Nov 2026 20:30:31 +0530 Subject: [PATCH 1/2] Don't show an expand arrow next to String variables The VM service reports the number of code units of a String as the `InstanceRef.length`. `DartObjectNode.childCount` returns that length, so `isExpandable` treated every non-empty String as having children and showed a `>` next to String fields in the debugger variables tree, even though expanding them shows nothing. Ignore `childCount` for String instances when deciding whether a node is expandable. `childCount` itself is unchanged, since `isPartialObject` and `getObject` rely on it. Fixes https://github.com/flutter/devtools/issues/5377 --- .../shared/diagnostics/dart_object_node.dart | 10 ++++- .../diagnostics/dart_object_node_test.dart | 38 +++++++++++++++++++ .../test/test_infra/utils/variable_utils.dart | 7 +++- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/packages/devtools_app/lib/src/shared/diagnostics/dart_object_node.dart b/packages/devtools_app/lib/src/shared/diagnostics/dart_object_node.dart index 5b0ac2a9129..e61e6a43739 100644 --- a/packages/devtools_app/lib/src/shared/diagnostics/dart_object_node.dart +++ b/packages/devtools_app/lib/src/shared/diagnostics/dart_object_node.dart @@ -267,8 +267,14 @@ class DartObjectNode extends TreeNode { if (isRootForReferences(ref)) return true; - if (treeInitializeComplete || children.isNotEmpty || childCount > 0) { - return children.isNotEmpty || childCount > 0; + // For a String, the VM service reports the number of code units as the + // instance length, so a non-zero [childCount] does not mean the String has + // child nodes to expand into. + final hasChildNodes = + children.isNotEmpty || + (childCount > 0 && instanceRef?.kind != InstanceKind.kString); + if (treeInitializeComplete || hasChildNodes) { + return hasChildNodes; } final diagnostic = theRef?.diagnostic; if (diagnostic != null && diff --git a/packages/devtools_app/test/shared/diagnostics/dart_object_node_test.dart b/packages/devtools_app/test/shared/diagnostics/dart_object_node_test.dart index 95be5046d8a..a96a43495a5 100644 --- a/packages/devtools_app/test/shared/diagnostics/dart_object_node_test.dart +++ b/packages/devtools_app/test/shared/diagnostics/dart_object_node_test.dart @@ -106,6 +106,44 @@ void main() { expect(str.isPartialObject, isFalse); }); + group('isExpandable', () { + test('is false for a string without a length', () { + final str = buildStringVariable('Hello there!'); + expect(str.isExpandable, isFalse); + }); + + // Regression test for https://github.com/flutter/devtools/issues/5377. + test('is false for a string with a length', () { + const value = 'Hello there!'; + final str = buildStringVariable(value, length: value.length); + expect(str.childCount, equals(value.length)); + expect(str.isPartialObject, isFalse); + expect(str.isExpandable, isFalse); + }); + + test('is false for a string after its tree is initialized', () { + const value = 'Hello there!'; + final str = buildStringVariable(value, length: value.length) + ..treeInitializeComplete = true; + expect(str.isExpandable, isFalse); + }); + + test('is false for a boolean', () { + final boolean = buildBooleanVariable(true); + expect(boolean.isExpandable, isFalse); + }); + + test('is true for a non-empty list', () { + final list = buildListVariable(length: 3); + expect(list.isExpandable, isTrue); + }); + + test('is true for a non-empty map', () { + final map = buildMapVariable(length: 3); + expect(map.isExpandable, isTrue); + }); + }); + group('toString', () { test('string variable', () { final str = buildStringVariable('Hello there!'); diff --git a/packages/devtools_app/test/test_infra/utils/variable_utils.dart b/packages/devtools_app/test/test_infra/utils/variable_utils.dart index 1515c977ff9..27a87aceff6 100644 --- a/packages/devtools_app/test/test_infra/utils/variable_utils.dart +++ b/packages/devtools_app/test/test_infra/utils/variable_utils.dart @@ -176,7 +176,11 @@ DartObjectNode buildSetGroupingVariable({ ); } -DartObjectNode buildStringVariable(String value) { +/// Builds a [DartObjectNode] for a String with the given [value]. +/// +/// The VM service reports the number of code units of a String as the +/// [InstanceRef.length], so pass [length] to mirror what a live VM sends. +DartObjectNode buildStringVariable(String value, {int? length}) { return DartObjectNode.create( BoundVariable( name: _incrementRoot(), @@ -190,6 +194,7 @@ DartObjectNode buildStringVariable(String value) { ), valueAsString: value, valueAsStringIsTruncated: true, + length: length, ), ), _isolateRef, From b5421930b017194b1e2470703285431711f8fc27 Mon Sep 17 00:00:00 2001 From: Abhilash-Puthukkudi Date: Sun, 29 Nov 2026 20:30:49 +0530 Subject: [PATCH 2/2] Add release note for String expand arrow fix --- packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md b/packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md index db139f83125..a2a660a1f3e 100644 --- a/packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md +++ b/packages/devtools_app/release_notes/NEXT_RELEASE_NOTES.md @@ -64,7 +64,9 @@ TODO: Remove this section if there are not any updates. ## Debugger updates -TODO: Remove this section if there are not any updates. +* Fixed an issue where String variables showed an expand arrow (`>`) in the + variables tree even though they cannot be expanded. + [#5377](https://github.com/flutter/devtools/issues/5377) ## Network profiler updates