Skip to content

Commit

Permalink
turn queryRef symbols into Symbol.for calls (#12409)
Browse files Browse the repository at this point in the history
* turn queryRef symbols into `Symbol.for` calls

* Clean up Prettier, Size-limit, and Api-Extractor

---------

Co-authored-by: phryneas <[email protected]>
  • Loading branch information
phryneas and phryneas authored Mar 6, 2025
1 parent 4332b88 commit 6aa2f3e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 7 deletions.
5 changes: 5 additions & 0 deletions .changeset/grumpy-dogs-add.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@apollo/client": patch
---

To mitigate problems when Apollo Client ends up more than once in the bundle, some unique symbols were converted into `Symbol.for` calls.
2 changes: 1 addition & 1 deletion .size-limits.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"dist/apollo-client.min.cjs": 42231,
"dist/apollo-client.min.cjs": 42243,
"import { ApolloClient, InMemoryCache, HttpLink } from \"dist/index.js\" (production)": 34437
}
5 changes: 3 additions & 2 deletions src/react/hooks/useLazyQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import * as React from "rehackt";
import type {
ApolloClient,
ApolloQueryResult,
ObservableQuery,
OperationVariables,
WatchQueryOptions,
} from "../../core/index.js";
Expand All @@ -17,7 +18,7 @@ import type {
QueryHookOptions,
QueryResult,
} from "../types/types.js";
import type { InternalResult, ObsQueryWithMeta } from "./useQuery.js";
import type { InternalResult } from "./useQuery.js";
import {
createMakeWatchQueryOptions,
getDefaultFetchPolicy,
Expand Down Expand Up @@ -203,7 +204,7 @@ export function useLazyQuery<

function executeQuery<TData, TVariables extends OperationVariables>(
resultData: InternalResult<TData, TVariables>,
observable: ObsQueryWithMeta<TData, TVariables>,
observable: ObservableQuery<TData, TVariables>,
client: ApolloClient<object>,
currentQuery: DocumentNode,
options: QueryHookOptions<TData, TVariables> & {
Expand Down
4 changes: 2 additions & 2 deletions src/react/hooks/useQuery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ type InternalQueryResult<TData, TVariables extends OperationVariables> = Omit<
>;

function noop() {}
export const lastWatchOptions = Symbol();
const lastWatchOptions = Symbol();

export interface ObsQueryWithMeta<TData, TVariables extends OperationVariables>
interface ObsQueryWithMeta<TData, TVariables extends OperationVariables>
extends ObservableQuery<TData, TVariables> {
[lastWatchOptions]?: WatchQueryOptions<TVariables, TData>;
}
Expand Down
6 changes: 4 additions & 2 deletions src/react/internal/cache/QueryReference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ type FetchMoreOptions<TData> = Parameters<
ObservableQuery<TData>["fetchMore"]
>[0];

const QUERY_REFERENCE_SYMBOL: unique symbol = Symbol();
const PROMISE_SYMBOL: unique symbol = Symbol();
const QUERY_REFERENCE_SYMBOL: unique symbol = Symbol.for(
"apollo.internal.queryRef"
);
const PROMISE_SYMBOL: unique symbol = Symbol.for("apollo.internal.refPromise");
declare const QUERY_REF_BRAND: unique symbol;
/**
* A `QueryReference` is an opaque object returned by `useBackgroundQuery`.
Expand Down

0 comments on commit 6aa2f3e

Please sign in to comment.