Skip to content

Commit 6063570

Browse files
committed
fix: add production guard
1 parent 3c863dd commit 6063570

4 files changed

Lines changed: 31 additions & 17 deletions

File tree

packages/gqty/src/Accessor/resolve.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,10 @@ const createObjectProxyHandler = (
225225
ownKeys(target) {
226226
// When activeEnumerators > 0 (e.g., selectFields helper), always
227227
// return all schema keys regardless of cache state.
228-
if (context.activeEnumerators > 0) {
228+
if (
229+
process.env.NODE_ENV === 'production' ||
230+
context.activeEnumerators > 0
231+
) {
229232
return Reflect.ownKeys(target).filter(
230233
(k) => typeof k === 'string'
231234
) as string[];

packages/gqty/src/Helpers/getFields.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,11 @@ export function getFields<
77
>(accessor: TAccesorData, ...keys: TAccesorKeys[]): TAccesorData {
88
if (!isObject(accessor)) return accessor;
99

10-
// Allow enumeration to see all schema fields, not just cached ones
11-
const meta = $meta(accessor);
10+
// Allow enumeration to see all schema fields, not just cached ones.
11+
// Only needed in dev mode where we restrict ownKeys to prevent React 19's
12+
// prop diffing from triggering selections.
13+
const meta =
14+
process.env.NODE_ENV !== 'production' ? $meta(accessor) : undefined;
1215
if (meta) {
1316
meta.context.activeEnumerators++;
1417
}

packages/gqty/src/Helpers/selectFields.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ export function selectFields<A extends object | null | undefined>(
2424
return {} as A;
2525
}
2626

27-
// Allow enumeration to see all schema fields, not just cached ones
28-
const meta = $meta(accessor);
27+
// Allow enumeration to see all schema fields, not just cached ones.
28+
// Only needed in dev mode where we restrict ownKeys to prevent React 19's
29+
// prop diffing from triggering selections.
30+
const meta =
31+
process.env.NODE_ENV !== 'production' ? $meta(accessor) : undefined;
2932
if (meta) {
3033
meta.context.activeEnumerators++;
3134
}

packages/react/src/query/useQuery.ts

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -548,20 +548,25 @@ export const createUseQuery = <TSchema extends BaseGeneratedSchema>(
548548
: query;
549549

550550
return new Proxy(target, {
551-
// Only expose $refetch and $state in enumeration.
551+
// Only expose $refetch and $state in enumeration in dev mode.
552552
// This prevents React 19 dev mode from enumerating all schema fields
553553
// during prop diffing, which would trigger unintended selections.
554-
// Users who need to enumerate query fields should access the underlying
555-
// accessor directly or use selectFields/getFields helpers.
556-
ownKeys: () => ['$refetch', '$state'],
557-
558-
getOwnPropertyDescriptor: (target, key) => {
559-
if (key === '$refetch' || key === '$state') {
560-
return Reflect.getOwnPropertyDescriptor(target, key);
561-
}
562-
// Return undefined for schema keys - they're not "own" properties
563-
return undefined;
564-
},
554+
// In production, return actual target keys (just $refetch and $state).
555+
ownKeys:
556+
process.env.NODE_ENV !== 'production'
557+
? () => ['$refetch', '$state']
558+
: undefined,
559+
560+
getOwnPropertyDescriptor:
561+
process.env.NODE_ENV !== 'production'
562+
? (target, key) => {
563+
if (key === '$refetch' || key === '$state') {
564+
return Reflect.getOwnPropertyDescriptor(target, key);
565+
}
566+
// Return undefined for schema keys - they're not "own" properties
567+
return undefined;
568+
}
569+
: undefined,
565570

566571
has: (_, key) => {
567572
// $refetch and $state are always present

0 commit comments

Comments
 (0)