* Starts resolving the `QueryClient` from context, unless one was passed * explicitly, and calls `onConnected` in a microtask so subclass fields are * initialized first.
()
| 51 | * initialized first. |
| 52 | */ |
| 53 | hostConnected(): void { |
| 54 | if (this.connected || this.destroyed) { |
| 55 | return |
| 56 | } |
| 57 | |
| 58 | this.connected = true |
| 59 | let contextResolutionAttempt: number | undefined |
| 60 | |
| 61 | if (this.explicitClient) { |
| 62 | this.queryClientResolutionState = 'bound' |
| 63 | } else { |
| 64 | contextResolutionAttempt = ++this.connectionAttempt |
| 65 | this.beginContextResolution() |
| 66 | } |
| 67 | |
| 68 | // Defer onConnected to ensure subclass constructors complete before |
| 69 | // lifecycle callbacks access subclass state. This handles the case where |
| 70 | // addController is called on an already-connected host (e.g., during |
| 71 | // willUpdate), which synchronously triggers hostConnected before |
| 72 | // subclass field initialization. |
| 73 | queueMicrotask(() => { |
| 74 | if (this.connected && !this.destroyed) { |
| 75 | this.onConnected() |
| 76 | } |
| 77 | }) |
| 78 | |
| 79 | if (contextResolutionAttempt !== undefined) { |
| 80 | // Provider-backed controllers on already-connected hosts should finish |
| 81 | // their deferred onConnected pass before a context client binds. |
| 82 | this.queueContextResolution(contextResolutionAttempt) |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Releases the context `QueryClient`, unless one was passed explicitly, and |
nothing calls this directly
no test coverage detected