Skip to content

🤖🤖🤖 fix: disable MockedProvider devtools by default - #13348

Closed
cyphercodes wants to merge 1 commit into
apollographql:mainfrom
cyphercodes:fix-mockedprovider-devtools-default
Closed

🤖🤖🤖 fix: disable MockedProvider devtools by default#13348
cyphercodes wants to merge 1 commit into
apollographql:mainfrom
cyphercodes:fix-mockedprovider-devtools-default

Conversation

@cyphercodes

@cyphercodes cyphercodes commented Jul 23, 2026

Copy link
Copy Markdown

Fixes #13344

Summary

  • Restore the MockedProvider behavior from MockedProvider: default connectToDevTools: false #11289 by disabling Apollo Client DevTools unless devtools is explicitly provided.
  • Add regression coverage that verifies the default does not register window.__APOLLO_CLIENT__ while devtools={{ enabled: true }} still opts in.
  • Add a patch changeset.

Checklist:

  • If this PR contains changes to the library itself (not necessary for e.g. docs updates), please include a changeset (see CONTRIBUTING.md)
  • If this PR is a new feature, please reference an issue where a consensus about the design was reached (not necessary for small changes)
  • Make sure all of the significant new logic is covered by tests

Tests

  • npm run test -- --runInBand --testRegex src/testing/react/__tests__/MockedProvider.test.tsx
  • npm exec -- prettier --check src/testing/react/MockedProvider.tsx src/testing/react/__tests__/MockedProvider.test.tsx .changeset/proud-cooks-sip.md
  • git diff --check

Note: a focused ESLint run was attempted, but the local clone lacked generated docs/public/canonical-references.json, causing ESLint config loading to fail before linting changed files.

Summary by CodeRabbit

  • Bug Fixes

    • DevTools are now disabled by default when using MockedProvider, preventing unintended global DevTools registration.
    • DevTools can still be explicitly enabled through the provider configuration.
  • Documentation

    • Added a patch release note describing the updated default behavior.

@apollo-librarian

apollo-librarian Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

✅ AI Style Review — No Changes Detected

No MDX files were changed in this pull request.

Review Log: View detailed log

This review is AI-generated. Please use common sense when accepting these suggestions, as they may not always be accurate or appropriate for your specific context.

@apollo-cla

Copy link
Copy Markdown

@cyphercodes: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@changeset-bot

changeset-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 015f8fd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@apollo/client Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

MockedProvider now disables Apollo Client DevTools unless callers explicitly enable them. Tests verify the default disabled state, opt-in behavior, global client registration, cleanup, and timer handling. A patch changeset documents the behavior.

Changes

MockedProvider DevTools behavior

Layer / File(s) Summary
DevTools default and validation
src/testing/react/MockedProvider.tsx, src/testing/react/__tests__/MockedProvider.test.tsx, .changeset/proud-cooks-sip.md
MockedProvider passes { enabled: false } when devtools is omitted; tests cover disabled-by-default and explicitly enabled configurations, and a patch changeset records the change.

Estimated code review effort: 2 (Simple) | ~10 minutes

Poem

A rabbit peeked at tools in flight,
Then tucked them safely out of sight.
“Hop in,” said MockedProvider,
“Opt in when you need them brighter!”
Tests thumped twice; the patch took flight.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: disabling MockedProvider devtools by default.
Linked Issues check ✅ Passed The PR restores the default no-devtools behavior and adds opt-in tests, matching #13344.
Out of Scope Changes check ✅ Passed The changes stay focused on the MockedProvider devtools default and its regression tests.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

ESLint install timed out. The project may have too many dependencies for the sandbox.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/testing/react/__tests__/MockedProvider.test.tsx`:
- Around line 104-115: Update the “should allow Apollo Client DevTools to be
enabled” test to flush the pending DevTools fallback timer and assert timer
cleanup while window is still active, after unmounting the MockedProvider. Wrap
fake-timer setup and test execution in a finally block that always restores real
timers, preserving the existing DevTools and global-client assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro Plus

Run ID: 5680d913-3124-4695-924e-a9b49362ab89

📥 Commits

Reviewing files that changed from the base of the PR and between 4bb6df7 and 015f8fd.

📒 Files selected for processing (3)
  • .changeset/proud-cooks-sip.md
  • src/testing/react/MockedProvider.tsx
  • src/testing/react/__tests__/MockedProvider.test.tsx

Comment on lines +104 to +115
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();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 -200

Repository: 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}")
PY

Repository: 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.ts

Repository: apollographql/apollo-client

Length of output: 10089


Flush the DevTools fallback timer while window is still active.

connectToDevTools() schedules the 10s fallback timeout before MockedProvider can call client.stop(), but this test never advances or asserts pending timers before jsdom teardown. Run pending timers and assert they clean up while window is still available, and restore real timers in a finally block so assertion failures cannot leave other tests running on fake timers.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/testing/react/__tests__/MockedProvider.test.tsx` around lines 104 - 115,
Update the “should allow Apollo Client DevTools to be enabled” test to flush the
pending DevTools fallback timer and assert timer cleanup while window is still
active, after unmounting the MockedProvider. Wrap fake-timer setup and test
execution in a finally block that always restores real timers, preserving the
existing DevTools and global-client assertions.

}),
localState,
devtools,
devtools: devtools ?? { enabled: false },

Copy link
Copy Markdown
Member

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 ApolloClient instance created in similar situations will still cause the same result.

@phryneas

Copy link
Copy Markdown
Member

Your PR doesn't actually solve the underlying problem but merely a symptom, and we're going a different direction.

I'm sorry, but please don't open drive-by AI-PRs without discussing the solution you're going for on the issue first.
This adds a lot of maintenance burden and puts us in a situation where we have to say "no" to a PR, which honestly I hate to do :/

We're going with #13349 which is a solution that @jerelmiller and I had already discussed yesterday. If you had checked in with us first, we could have saved you the money for the tokens 😞

@phryneas phryneas closed this Jul 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

3 participants