Skip to content

Commit cebb9d2

Browse files
hawkgspkozlowski-opensource
authored andcommitted
refactor(devtools): disable unsupported features (angular#60585)
Prepare the app for Wiz & ACX and handle unsupported features by disabling their respective UI. PR Close angular#60585
1 parent 8aaefa7 commit cebb9d2

26 files changed

+372
-121
lines changed

devtools/projects/ng-devtools-backend/src/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ ts_library(
77
srcs = ["public-api.ts"],
88
deps = [
99
"//devtools/projects/ng-devtools-backend/src/lib",
10-
"//devtools/projects/ng-devtools-backend/src/lib:component_tree",
10+
"//devtools/projects/ng-devtools-backend/src/lib/component-tree",
1111
],
1212
)

devtools/projects/ng-devtools-backend/src/lib/BUILD.bazel

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ ts_library(
158158
name = "client_event_subscribers",
159159
srcs = ["client-event-subscribers.ts"],
160160
deps = [
161-
":component_tree",
162161
":highlighter",
163162
":interfaces",
164163
":router_tree",
165164
":set_console_reference",
166165
":utils",
167166
"//devtools/projects/ng-devtools-backend/src/lib/component-inspector",
167+
"//devtools/projects/ng-devtools-backend/src/lib/component-tree",
168168
"//devtools/projects/ng-devtools-backend/src/lib/hooks",
169169
"//devtools/projects/ng-devtools-backend/src/lib/ng-debug-api",
170170
"//devtools/projects/ng-devtools-backend/src/lib/state-serializer",
@@ -173,33 +173,3 @@ ts_library(
173173
"@npm//rxjs",
174174
],
175175
)
176-
177-
ts_library(
178-
name = "component_tree",
179-
srcs = ["component-tree.ts"],
180-
deps = [
181-
":interfaces",
182-
":property_mutation",
183-
":utils",
184-
"//devtools/projects/ng-devtools-backend/src/lib/directive-forest",
185-
"//devtools/projects/ng-devtools-backend/src/lib/ng-debug-api",
186-
"//devtools/projects/ng-devtools-backend/src/lib/state-serializer",
187-
"//devtools/projects/protocol",
188-
"//packages/core",
189-
],
190-
)
191-
192-
ts_test_library(
193-
name = "component_tree_test_lib",
194-
srcs = ["component-tree.spec.ts"],
195-
deps = [
196-
":component_tree",
197-
"//packages/core",
198-
"@npm//jasmine",
199-
],
200-
)
201-
202-
karma_web_test_suite(
203-
name = "component_tree_test",
204-
deps = [":component_tree_test_lib"],
205-
)

devtools/projects/ng-devtools-backend/src/lib/client-event-subscribers.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ import {
4545
serializeProviderRecord,
4646
serializeResolutionPath,
4747
updateState,
48-
} from './component-tree';
48+
} from './component-tree/component-tree';
4949
import {unHighlight} from './highlighter';
5050
import {disableTimingAPI, enableTimingAPI, initializeOrGetDirectiveForestHooks} from './hooks';
5151
import {start as startProfiling, stop as stopProfiling} from './hooks/capture';
@@ -56,6 +56,7 @@ import {setConsoleReference} from './set-console-reference';
5656
import {serializeDirectiveState} from './state-serializer/state-serializer';
5757
import {runOutsideAngular, unwrapSignal} from './utils';
5858
import {DirectiveForestHooks} from './hooks/hooks';
59+
import {getSupportedApis} from './ng-debug-api/supported-apis';
5960

6061
type InspectorRef = {ref: ComponentInspector | null};
6162

@@ -337,6 +338,7 @@ const checkForAngular = (messageBus: MessageBus<Events>): void => {
337338
devMode: appIsAngularInDevMode(),
338339
ivy: appIsIvy,
339340
hydration: isHydrationEnabled(),
341+
supportedApis: getSupportedApis(),
340342
},
341343
]);
342344
};

devtools/projects/ng-devtools-backend/src/lib/component-inspector/BUILD.bazel

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
load("//devtools/tools:typescript.bzl", "ts_library", "ts_test_library")
21
load("//devtools/tools:defaults.bzl", "karma_web_test_suite")
2+
load("//devtools/tools:typescript.bzl", "ts_library", "ts_test_library")
33

44
package(default_visibility = ["//visibility:public"])
55

66
ts_library(
77
name = "component-inspector",
88
srcs = ["component-inspector.ts"],
99
deps = [
10-
"//devtools/projects/ng-devtools-backend/src/lib:component_tree",
1110
"//devtools/projects/ng-devtools-backend/src/lib:highlighter",
1211
"//devtools/projects/ng-devtools-backend/src/lib:interfaces",
12+
"//devtools/projects/ng-devtools-backend/src/lib/component-tree",
1313
"//devtools/projects/ng-devtools-backend/src/lib/hooks",
1414
"//devtools/projects/protocol",
1515
],
@@ -27,10 +27,10 @@ ts_test_library(
2727
],
2828
deps = [
2929
":component-inspector",
30-
"//devtools/projects/ng-devtools-backend/src/lib:component_tree",
3130
"//devtools/projects/ng-devtools-backend/src/lib:highlighter",
3231
"//devtools/projects/ng-devtools-backend/src/lib:interfaces",
3332
"//devtools/projects/ng-devtools-backend/src/lib:utils",
33+
"//devtools/projects/ng-devtools-backend/src/lib/component-tree",
3434
"//devtools/projects/ng-devtools-backend/src/lib/hooks",
3535
"//devtools/projects/protocol",
3636
"//packages/core",

devtools/projects/ng-devtools-backend/src/lib/component-inspector/component-inspector.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {ElementPosition, HydrationStatus} from 'protocol';
1010

11-
import {findNodeInForest} from '../component-tree';
11+
import {findNodeInForest} from '../component-tree/component-tree';
1212
import {
1313
findComponentAndHost,
1414
highlightHydrationElement,
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
load("//devtools/tools:defaults.bzl", "karma_web_test_suite")
2+
load("//devtools/tools:typescript.bzl", "ts_library", "ts_test_library")
3+
4+
package(default_visibility = ["//visibility:public"])
5+
6+
ts_library(
7+
name = "get-roots",
8+
srcs = ["get-roots.ts"],
9+
)
10+
11+
ts_library(
12+
name = "core-enums",
13+
srcs = ["core-enums.ts"],
14+
)
15+
16+
ts_library(
17+
name = "component-tree",
18+
srcs = ["component-tree.ts"],
19+
deps = [
20+
":core-enums",
21+
":get-roots",
22+
"//devtools/projects/ng-devtools-backend/src/lib:interfaces",
23+
"//devtools/projects/ng-devtools-backend/src/lib:property_mutation",
24+
"//devtools/projects/ng-devtools-backend/src/lib:utils",
25+
"//devtools/projects/ng-devtools-backend/src/lib/directive-forest",
26+
"//devtools/projects/ng-devtools-backend/src/lib/ng-debug-api",
27+
"//devtools/projects/ng-devtools-backend/src/lib/state-serializer",
28+
"//devtools/projects/protocol",
29+
"//packages/core",
30+
],
31+
)
32+
33+
ts_test_library(
34+
name = "test_lib",
35+
srcs = glob(["*.spec.ts"]),
36+
deps = [
37+
":component-tree",
38+
":get-roots",
39+
"//packages/core",
40+
"@npm//jasmine",
41+
],
42+
)
43+
44+
karma_web_test_suite(
45+
name = "test",
46+
deps = [":test_lib"],
47+
)

devtools/projects/ng-devtools-backend/src/lib/component-tree.ts renamed to devtools/projects/ng-devtools-backend/src/lib/component-tree/component-tree.ts

Lines changed: 10 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -30,38 +30,23 @@ import {
3030
SerializedProviderRecord,
3131
UpdatedStateData,
3232
} from 'protocol';
33-
import {buildDirectiveTree, getLViewFromDirectiveOrElementInstance} from './directive-forest/index';
33+
import {
34+
buildDirectiveTree,
35+
getLViewFromDirectiveOrElementInstance,
36+
} from '../directive-forest/index';
3437
import {
3538
ngDebugApiIsSupported,
3639
ngDebugClient,
3740
ngDebugDependencyInjectionApiIsSupported,
38-
} from './ng-debug-api/ng-debug-api';
41+
} from '../ng-debug-api/ng-debug-api';
3942
import {
4043
deeplySerializeSelectedProperties,
4144
serializeDirectiveState,
42-
} from './state-serializer/state-serializer';
43-
import {mutateNestedProp} from './property-mutation';
44-
import {ComponentTreeNode, DirectiveInstanceType, ComponentInstanceType} from './interfaces';
45-
46-
// Need to be kept in sync with Angular framework
47-
// We can't directly import it from framework now
48-
// because this also pulls up the security policies
49-
// for Trusted Types, which we reinstantiate.
50-
enum ChangeDetectionStrategy {
51-
OnPush = 0,
52-
Default = 1,
53-
}
54-
55-
enum AcxChangeDetectionStrategy {
56-
Default = 0,
57-
OnPush = 1,
58-
}
59-
60-
enum Framework {
61-
Angular = 'angular',
62-
ACX = 'acx',
63-
Wiz = 'wiz',
64-
}
45+
} from '../state-serializer/state-serializer';
46+
import {mutateNestedProp} from '../property-mutation';
47+
import {ComponentTreeNode, DirectiveInstanceType, ComponentInstanceType} from '../interfaces';
48+
import {getRoots} from './get-roots';
49+
import {AcxChangeDetectionStrategy, ChangeDetectionStrategy, Framework} from './core-enums';
6550

6651
export const injectorToId = new WeakMap<Injector | HTMLElement, string>();
6752
export const nodeInjectorToResolutionPath = new WeakMap<HTMLElement, SerializedInjector[]>();
@@ -559,25 +544,6 @@ const getRootLViewsHelper = (element: Element, rootLViews = new Set<any>()): Set
559544
return rootLViews;
560545
};
561546

562-
const getRoots = () => {
563-
const roots = Array.from(document.documentElement.querySelectorAll('[ng-version]'));
564-
565-
const isTopLevel = (element: Element) => {
566-
let parent: Element | null = element;
567-
568-
while (parent?.parentElement) {
569-
parent = parent.parentElement;
570-
if (parent.hasAttribute('ng-version')) {
571-
return false;
572-
}
573-
}
574-
575-
return true;
576-
};
577-
578-
return roots.filter(isTopLevel);
579-
};
580-
581547
export const buildDirectiveForest = (): ComponentTreeNode[] => {
582548
const roots = getRoots();
583549
return Array.prototype.concat.apply([], Array.from(roots).map(buildDirectiveTree));
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
// Need to be kept in sync with Angular framework
10+
// We can't directly import it from framework now
11+
// because this also pulls up the security policies
12+
// for Trusted Types, which we reinstantiate.
13+
export enum ChangeDetectionStrategy {
14+
OnPush = 0,
15+
Default = 1,
16+
}
17+
18+
export enum AcxChangeDetectionStrategy {
19+
Default = 0,
20+
OnPush = 1,
21+
}
22+
23+
export enum Framework {
24+
Angular = 'angular',
25+
ACX = 'acx',
26+
Wiz = 'wiz',
27+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
import {getRoots} from './get-roots';
10+
11+
function createRoot() {
12+
const root = document.createElement('div');
13+
root.setAttribute('ng-version', '');
14+
return root;
15+
}
16+
17+
describe('getRoots', () => {
18+
afterEach(() => {
19+
document.body.replaceChildren();
20+
});
21+
22+
it('should return root element', () => {
23+
const rootElement = createRoot();
24+
const childElement = createRoot();
25+
26+
rootElement.appendChild(childElement);
27+
document.body.appendChild(rootElement);
28+
29+
const roots = getRoots();
30+
31+
expect(roots.length).toEqual(1);
32+
expect(roots.pop()).toEqual(rootElement);
33+
});
34+
35+
it('should return root elements', () => {
36+
const firstRoot = createRoot();
37+
const secondRoot = createRoot();
38+
39+
document.body.appendChild(firstRoot);
40+
document.body.appendChild(secondRoot);
41+
42+
const roots = getRoots();
43+
44+
expect(roots.length).toEqual(2);
45+
expect(roots).toContain(firstRoot);
46+
expect(roots).toContain(secondRoot);
47+
});
48+
});
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* @license
3+
* Copyright Google LLC All Rights Reserved.
4+
*
5+
* Use of this source code is governed by an MIT-style license that can be
6+
* found in the LICENSE file at https://angular.dev/license
7+
*/
8+
9+
/** Returns all app roots. */
10+
export function getRoots(): Element[] {
11+
const roots = Array.from(document.documentElement.querySelectorAll('[ng-version]'));
12+
13+
const isTopLevel = (element: Element) => {
14+
let parent: Element | null = element;
15+
16+
while (parent?.parentElement) {
17+
parent = parent.parentElement;
18+
if (parent.hasAttribute('ng-version')) {
19+
return false;
20+
}
21+
}
22+
23+
return true;
24+
};
25+
26+
return roots.filter(isTopLevel);
27+
}

devtools/projects/ng-devtools-backend/src/lib/hooks/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ ts_library(
2525
name = "identity_tracker",
2626
srcs = ["identity-tracker.ts"],
2727
deps = [
28-
"//devtools/projects/ng-devtools-backend/src/lib:component_tree",
2928
"//devtools/projects/ng-devtools-backend/src/lib:interfaces",
29+
"//devtools/projects/ng-devtools-backend/src/lib/component-tree",
3030
"//devtools/projects/protocol",
3131
],
3232
)

devtools/projects/ng-devtools-backend/src/lib/hooks/identity-tracker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import {DevToolsNode, ElementPosition} from 'protocol';
1010

11-
import {buildDirectiveForest} from '../component-tree';
11+
import {buildDirectiveForest} from '../component-tree/component-tree';
1212
import {ComponentInstanceType, ComponentTreeNode, DirectiveInstanceType} from '../interfaces';
1313

1414
export declare interface Type<T> extends Function {

devtools/projects/ng-devtools-backend/src/lib/ng-debug-api/BUILD.bazel

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ ng_module(
1111
exclude = ["*.spec.ts"],
1212
),
1313
deps = [
14+
"//devtools/projects/ng-devtools-backend/src/lib/component-tree:core-enums",
15+
"//devtools/projects/ng-devtools-backend/src/lib/component-tree:get-roots",
16+
"//devtools/projects/protocol",
1417
"//packages/core",
1518
],
1619
)
@@ -20,6 +23,7 @@ ts_test_library(
2023
srcs = ["ng-debug-api.spec.ts"],
2124
deps = [
2225
":ng-debug-api",
26+
"//devtools/projects/ng-devtools-backend/src/lib/component-tree:core-enums",
2327
"//packages/core",
2428
"@npm//jasmine",
2529
],

0 commit comments

Comments
 (0)