MCPcopy Create free account
hub / github.com/TanStack/query / hostConnected

Function hostConnected

packages/lit-query/src/controllers/BaseController.ts:53–84  ·  view source on GitHub ↗

* Starts resolving the `QueryClient` from context, unless one was passed * explicitly, and calls `onConnected` in a microtask so subclass fields are * initialized first.

()

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls 1

onConnectedMethod · 0.45

Tested by

no test coverage detected