Skip to content

Commit b406ac0

Browse files
committed
fix: inspector (#3104)
### TL;DR Fixed query key indexing in actor queries context and added default timestamp-based hash generation. ### What changed? - Fixed the `queryFn` implementations to correctly access the `actorId` from the query key array at index 2 instead of index 1 - Added a default value for the `hash` parameter that uses the current timestamp (`Date.now()`) when no hash is provided ### How to test? 1. Verify that actor queries work correctly by navigating to the actor inspector in the UI 2. Test with both explicit hash values and without providing a hash to ensure the default timestamp-based hash works properly 3. Confirm that all actor-related queries (ping, state, connections, database, events, RPCs, auto-wake-up) function as expected ### Why make this change? The previous implementation had incorrect indexing when accessing query key elements, which could lead to undefined values and errors. The query key structure is `[hash, "actor", actorId, ...]`, so the `actorId` is at index 2, not index 1. Additionally, providing a default timestamp-based hash ensures that the context always has a unique identifier even when not explicitly provided.
1 parent 5abd6bb commit b406ac0

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

frontend/src/components/actors/actor-queries-context.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import type { ActorId } from "./queries";
55

66
type RequestOptions = Parameters<typeof createActorInspectorClient>[1];
77

8-
export const createDefaultActorContext = ({ hash }: { hash: string } = {}) => ({
8+
export const createDefaultActorContext = (
9+
{ hash }: { hash: string } = { hash: `${Date.now()}` },
10+
) => ({
911
createActorInspectorFetchConfiguration: (
1012
actorId: ActorId | string,
1113
): RequestOptions => ({
@@ -33,7 +35,7 @@ export const createDefaultActorContext = ({ hash }: { hash: string } = {}) => ({
3335
refetchInterval: 1000,
3436
...opts,
3537
queryKey: [hash, "actor", actorId, "ping"],
36-
queryFn: async ({ queryKey: [, actorId] }) => {
38+
queryFn: async ({ queryKey: [, , actorId] }) => {
3739
const client = this.createActorInspector(actorId);
3840
const response = await client.ping.$get();
3941
if (!response.ok) {
@@ -52,7 +54,7 @@ export const createDefaultActorContext = ({ hash }: { hash: string } = {}) => ({
5254
enabled,
5355
refetchInterval: 1000,
5456
queryKey: [hash, "actor", actorId, "state"],
55-
queryFn: async ({ queryKey: [, actorId] }) => {
57+
queryFn: async ({ queryKey: [, , actorId] }) => {
5658
const client = this.createActorInspector(actorId);
5759
const response = await client.state.$get();
5860

@@ -75,7 +77,7 @@ export const createDefaultActorContext = ({ hash }: { hash: string } = {}) => ({
7577
enabled,
7678
refetchInterval: 1000,
7779
queryKey: [hash, "actor", actorId, "connections"],
78-
queryFn: async ({ queryKey: [, actorId] }) => {
80+
queryFn: async ({ queryKey: [, , actorId] }) => {
7981
const client = this.createActorInspector(actorId);
8082
const response = await client.connections.$get();
8183

@@ -94,7 +96,7 @@ export const createDefaultActorContext = ({ hash }: { hash: string } = {}) => ({
9496
return queryOptions({
9597
enabled,
9698
queryKey: [hash, "actor", actorId, "database"],
97-
queryFn: async ({ queryKey: [, actorId] }) => {
99+
queryFn: async ({ queryKey: [, , actorId] }) => {
98100
const client = this.createActorInspector(actorId);
99101
const response = await client.db.$get();
100102

@@ -143,7 +145,7 @@ export const createDefaultActorContext = ({ hash }: { hash: string } = {}) => ({
143145
staleTime: 0,
144146
gcTime: 5000,
145147
queryKey: [hash, "actor", actorId, "database", table],
146-
queryFn: async ({ queryKey: [, actorId, , table] }) => {
148+
queryFn: async ({ queryKey: [, , actorId, , table] }) => {
147149
const client = this.createActorInspector(actorId);
148150
const response = await client.db.$post({
149151
json: { query: `SELECT * FROM ${table} LIMIT 500` },
@@ -164,7 +166,7 @@ export const createDefaultActorContext = ({ hash }: { hash: string } = {}) => ({
164166
enabled,
165167
refetchInterval: 1000,
166168
queryKey: [hash, "actor", actorId, "events"],
167-
queryFn: async ({ queryKey: [, actorId] }) => {
169+
queryFn: async ({ queryKey: [, , actorId] }) => {
168170
const client = this.createActorInspector(actorId);
169171
const response = await client.events.$get();
170172

@@ -183,7 +185,7 @@ export const createDefaultActorContext = ({ hash }: { hash: string } = {}) => ({
183185
return queryOptions({
184186
enabled,
185187
queryKey: [hash, "actor", actorId, "rpcs"],
186-
queryFn: async ({ queryKey: [, actorId] }) => {
188+
queryFn: async ({ queryKey: [, , actorId] }) => {
187189
const client = this.createActorInspector(actorId);
188190
const response = await client.rpcs.$get();
189191

@@ -234,7 +236,7 @@ export const createDefaultActorContext = ({ hash }: { hash: string } = {}) => ({
234236
staleTime: 0,
235237
gcTime: 0,
236238
queryKey: [hash, "actor", actorId, "auto-wake-up"],
237-
queryFn: async ({ queryKey: [, actorId] }) => {
239+
queryFn: async ({ queryKey: [, , actorId] }) => {
238240
const client = this.createActorInspector(actorId);
239241
try {
240242
await client.ping.$get();

0 commit comments

Comments
 (0)