@@ -14,7 +14,7 @@ import { getConfig } from "../lib/config";
1414import { ls } from "../lib/utils" ;
1515import { Button } from "../ui/button" ;
1616import { useFiltersValue } from "./actor-filters-context" ;
17- import { ActorProvider } from "./actor-queries-context" ;
17+ import { ActorProvider , useActor } from "./actor-queries-context" ;
1818import { Info } from "./actor-state-tab" ;
1919import { useDataProvider , useEngineCompatDataProvider } from "./data-provider" ;
2020import type { ActorId } from "./queries" ;
@@ -137,7 +137,13 @@ function ActorContextProvider(props: {
137137 ) ;
138138}
139139
140- function ActorInspectorProvider ( { children } : { children : ReactNode } ) {
140+ function ActorInspectorProvider ( {
141+ actorId,
142+ children,
143+ } : {
144+ actorId : ActorId ;
145+ children : ReactNode ;
146+ } ) {
141147 const { credentials } = useInspectorCredentials ( ) ;
142148
143149 if ( ! credentials ?. url || ! credentials ?. token ) {
@@ -150,7 +156,11 @@ function ActorInspectorProvider({ children }: { children: ReactNode }) {
150156 } ) ;
151157 } , [ credentials ] ) ;
152158
153- return < ActorProvider value = { actorContext } > { children } </ ActorProvider > ;
159+ return (
160+ < ActorProvider value = { actorContext } >
161+ < InspectorGuard actorId = { actorId } > { children } </ InspectorGuard >
162+ </ ActorProvider >
163+ ) ;
154164}
155165
156166function useActorRunner ( { actorId } : { actorId : ActorId } ) {
@@ -230,7 +240,11 @@ function ActorEngineProvider({
230240 ) ;
231241 }
232242
233- return < ActorProvider value = { actorContext } > { children } </ ActorProvider > ;
243+ return (
244+ < ActorProvider value = { actorContext } >
245+ < InspectorGuard actorId = { actorId } > { children } </ InspectorGuard >
246+ </ ActorProvider >
247+ ) ;
234248}
235249
236250function NoRunnerInfo ( { runner } : { runner : string } ) {
@@ -294,3 +308,36 @@ function AutoWakeUpActor({ actorId }: { actorId: ActorId }) {
294308 </ Info >
295309 ) ;
296310}
311+
312+ function InspectorGuard ( {
313+ actorId,
314+ children,
315+ } : {
316+ actorId : ActorId ;
317+ children : ReactNode ;
318+ } ) {
319+ const { isError } = useQuery ( {
320+ ...useActor ( ) . actorPingQueryOptions ( actorId ) ,
321+ enabled : true ,
322+ } ) ;
323+
324+ if ( isError ) {
325+ return (
326+ < InspectorGuardContext . Provider
327+ value = {
328+ < Info >
329+ < p > Unable to connect to the Actor's Inspector.</ p >
330+ < p >
331+ Check that your Actor has the Inspector enabled and
332+ that your network allows connections to the
333+ Inspector URL.
334+ </ p >
335+ </ Info >
336+ }
337+ >
338+ { children }
339+ </ InspectorGuardContext . Provider >
340+ ) ;
341+ }
342+ return children ;
343+ }
0 commit comments