-
Notifications
You must be signed in to change notification settings - Fork 2.9k
🤖🤖🤖 fix: disable MockedProvider devtools by default #13348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@apollo/client": patch | ||
| --- | ||
|
|
||
| Default `MockedProvider` to keep Apollo Client DevTools disabled unless explicitly configured. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,6 +90,31 @@ describe("General use", () => { | |
| errorThrown = false; | ||
| }); | ||
|
|
||
| it("should not connect to Apollo Client DevTools by default", () => { | ||
| delete (window as any).__APOLLO_CLIENT__; | ||
|
|
||
| const provider = new MockedProvider({}); | ||
|
|
||
| expect((provider as any).state.client.devtoolsConfig.enabled).toBe(false); | ||
| expect((window as any).__APOLLO_CLIENT__).toBeUndefined(); | ||
|
|
||
| provider.componentWillUnmount(); | ||
| }); | ||
|
|
||
| it("should allow Apollo Client DevTools to be enabled", () => { | ||
| jest.useFakeTimers(); | ||
| delete (window as any).__APOLLO_CLIENT__; | ||
|
|
||
| const provider = new MockedProvider({ devtools: { enabled: true } }); | ||
|
|
||
| expect((provider as any).state.client.devtoolsConfig.enabled).toBe(true); | ||
| expect((window as any).__APOLLO_CLIENT__).toBeDefined(); | ||
|
|
||
| delete (window as any).__APOLLO_CLIENT__; | ||
| provider.componentWillUnmount(); | ||
| jest.useRealTimers(); | ||
|
Comment on lines
+104
to
+115
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== files =="
fd -a 'MockedProvider.test.tsx|MockedProvider.tsx|.*devtools.*' . | sed 's#^\./##' | head -100
echo "== target file outline/size =="
if [ -f src/testing/react/__tests__/MockedProvider.test.tsx ]; then
wc -l src/testing/react/__tests__/MockedProvider.test.tsx
ast-grep outline src/testing/react/__tests__/MockedProvider.test.tsx || true
sed -n '1,180p' src/testing/react/__tests__/MockedProvider.test.tsx
fi
echo "== related devtools/MockedProvider sources =="
rg -n "devtoolsConfig|__APOLLO_CLIENT__|devtools:|setTimeout|setInterval|teardown|useFakeTimers|useRealTimers" src testing . -g '!node_modules' -g '!dist' -g '!build' | head -200Repository: apollographql/apollo-client Length of output: 25398 🏁 Script executed: #!/bin/bash
set -euo pipefail
python3 - <<'PY'
from pathlib import Path
p = Path('src/testing/react/__tests__/MockedProvider.test.tsx')
if not p.exists():
print("target_missing")
raise SystemExit
s = p.read_text()
for needle in ['delete (window as any).__APOLLO_CLIENT__', 'MockedProvider({ devtools: { enabled: true } })', '.flushAllTimers', 'runOnlyPendingTimers', 'runOnlyPendingTimersAsync', 'flushAllTimersAsync', 'useRealTimers', "afterEach"]:
print(f"{needle!r}: {needle in s}")
# Print relevant block with line numbers.
lines = s.splitlines()
for i,l in enumerate(lines,1):
if 100 <= i <= 125:
print(f"{i}: {l}")
PYRepository: apollographql/apollo-client Length of output: 1394 🏁 Script executed: #!/bin/bash
set -euo pipefail
echo "== ApolloClient devtools code =="
sed -n '1080,1215p' src/core/ApolloClient.ts
echo "== MockedProvider code =="
sed -n '1,105p' src/testing/react/MockedProvider.tsx
echo "== enableFakeTimers helper =="
sed -n '1,80p' src/testing/internal/disposables/enableFakeTimers.ts
echo "== setup fake timers globally if present =="
sed -n '1,140p' src/config/jest/setup.tsRepository: apollographql/apollo-client Length of output: 10089 Flush the DevTools fallback timer while
🤖 Prompt for AI Agents |
||
| }); | ||
|
|
||
| it("should mock the data", async () => { | ||
| using _disabledAct = disableActEnvironment(); | ||
| const { takeSnapshot } = await renderHookToSnapshotStream( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That doesn't solve the actual problem.
Any other
ApolloClientinstance created in similar situations will still cause the same result.