Skip to content

Commit 9f0a1ca

Browse files
committed
fix: address CodeRabbit review on NativeScript support
- overlay: close the socket when session setup fails after connecting, so retries don't leak open sockets - example: getPerson returns Person | undefined; detail page shows a not-found state - README: warn that --host 0.0.0.0 --no-auth exposes the server
1 parent 057aab6 commit 9f0a1ca

5 files changed

Lines changed: 49 additions & 22 deletions

File tree

‎README.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,13 @@ npx @santoshyadavdev/ng-devtools dev --host 0.0.0.0 --no-auth
368368
Then open `http://localhost:9999/` for the UI, or point an MCP client at
369369
`http://localhost:9999/__mcp`.
370370

371+
> [!WARNING]
372+
> `--host 0.0.0.0 --no-auth` exposes the devtools RPC and MCP endpoints,
373+
> unauthenticated, to every host that can reach your machine. Use it only on a
374+
> trusted network. The simulators reach the server over loopback, so drop
375+
> `--host 0.0.0.0` unless a physical device needs it, and prefer binding to the
376+
> one interface that device uses (e.g. `--host 192.168.1.20`).
377+
371378
### Example app
372379

373380
`examples/nativescript/` is a `ns create --ng` project wired up this way, with a small

‎examples/nativescript/src/app/people/person-detail.component.html‎

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,28 @@
1616
}
1717
</ActionBar>
1818

19-
<FlexboxLayout flexDirection="column">
20-
<FlexboxLayout class="m-4">
21-
<Label class="text-3xl text-gray-400" [text]="person()?.id + '. '"></Label>
22-
<Label class="text-3xl" [text]="person()?.name"></Label>
23-
</FlexboxLayout>
19+
@if (person(); as p) {
20+
<FlexboxLayout flexDirection="column">
21+
<FlexboxLayout class="m-4">
22+
<Label class="text-3xl text-gray-400" [text]="p.id + '. '"></Label>
23+
<Label class="text-3xl" [text]="p.name"></Label>
24+
</FlexboxLayout>
2425

25-
<StackLayout class="text-xl m-2 ml-6">
26-
<Label class="mb-2" fontWeight="700" text="Nationality:"></Label>
27-
<Label textWrap="true" [text]="person()?.nationality"></Label>
28-
</StackLayout>
26+
<StackLayout class="text-xl m-2 ml-6">
27+
<Label class="mb-2" fontWeight="700" text="Nationality:"></Label>
28+
<Label textWrap="true" [text]="p.nationality"></Label>
29+
</StackLayout>
2930

30-
<StackLayout class="text-xl m-2">
31-
<Label class="m-2 ml-4" fontWeight="700" text="Notable Achievements:"></Label>
32-
<Label
33-
class="text-xl m-2 ml-4"
34-
[text]="formatAchievements(person()?.notableAchievements)"
35-
textWrap="true"
36-
>
37-
</Label>
38-
</StackLayout>
39-
</FlexboxLayout>
31+
<StackLayout class="text-xl m-2">
32+
<Label class="m-2 ml-4" fontWeight="700" text="Notable Achievements:"></Label>
33+
<Label
34+
class="text-xl m-2 ml-4"
35+
[text]="formatAchievements(p.notableAchievements)"
36+
textWrap="true"
37+
>
38+
</Label>
39+
</StackLayout>
40+
</FlexboxLayout>
41+
} @else {
42+
<Label class="text-xl text-gray-500 m-4" text="Person not found."></Label>
43+
}

‎examples/nativescript/src/app/people/person-detail.component.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export class PersonDetailComponent implements OnInit {
2222
personService = inject(PersonService);
2323
routerExtensions = inject(RouterExtensions);
2424
route = inject(ActivatedRoute);
25-
person = signal<Person>(null);
25+
person = signal<Person | undefined>(undefined);
2626
isAndroid = __ANDROID__;
2727

2828
ngOnInit(): void {

‎examples/nativescript/src/app/people/person.service.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ export class PersonService {
113113
},
114114
]);
115115

116-
getPerson(id: number): Person {
116+
getPerson(id: number): Person | undefined {
117117
return this.items().find((person) => person.id === id);
118118
}
119119
}

‎packages/ng-devtools/src/overlay-nativescript.ts‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,23 @@ async function connect(baseURL: string, intervalMs: number, onDisconnected: () =
129129
},
130130
},
131131
});
132+
try {
133+
const stop = await startSession(rpc, intervalMs);
134+
return () => {
135+
closing = true;
136+
stop();
137+
};
138+
} catch (error) {
139+
closing = true;
140+
rpc.close?.();
141+
throw error;
142+
}
143+
}
144+
145+
async function startSession(
146+
rpc: Awaited<ReturnType<typeof connectDevframe>>,
147+
intervalMs: number,
148+
): Promise<() => void> {
132149
const my = rpc.scope('ng-devtools');
133150
const pageId = Math.random().toString(36).slice(2, 6);
134151

@@ -252,7 +269,6 @@ async function connect(baseURL: string, intervalMs: number, onDisconnected: () =
252269
});
253270

254271
return () => {
255-
closing = true;
256272
clearInterval(interval);
257273
restoreSignalHook();
258274
ngrx.stop();

0 commit comments

Comments
 (0)