snapshot of https://github.com/TanStack/query.git (main, 2026-09-16; blobs > 131072B omitted)
Some checks failed
autofix.ci / autofix (push) Failing after 4s
Release / Release (push) Has been skipped
GitHub Actions Security Analysis / Run zizmor (push) Failing after 2s

This commit is contained in:
upstream-mirror
2026-09-16 01:13:08 +05:00
commit 3a013ccdfe
3570 changed files with 490194 additions and 0 deletions

View File

@@ -0,0 +1,124 @@
import { QueryClient } from '@tanstack/query-core'
import { createQueryController } from '../build/modern/index.js'
class TestControllerHost {
controllers = new Set()
updatesRequested = 0
updateComplete = Promise.resolve(true)
addController(controller) {
this.controllers.add(controller)
}
removeController(controller) {
this.controllers.delete(controller)
}
requestUpdate() {
this.updatesRequested += 1
}
connect() {
for (const controller of this.controllers) {
controller.hostConnected?.()
}
}
disconnect() {
for (const controller of this.controllers) {
controller.hostDisconnected?.()
}
}
update() {
for (const controller of this.controllers) {
controller.hostUpdate?.()
}
for (const controller of this.controllers) {
controller.hostUpdated?.()
}
}
}
async function waitFor(assertion, timeoutMs = 3000) {
const startedAt = Date.now()
while (!assertion()) {
if (Date.now() - startedAt > timeoutMs) {
throw new Error(`Timed out waiting for assertion after ${timeoutMs}ms`)
}
await new Promise((resolve) => setTimeout(resolve, 5))
}
}
async function run(cycles = 1000) {
const client = new QueryClient({
defaultOptions: {
queries: {
retry: false,
gcTime: 0,
},
},
})
const queryKey = ['l3-stress']
const startedAt = Date.now()
const initialHeapMb = process.memoryUsage().heapUsed / (1024 * 1024)
for (let cycle = 0; cycle < cycles; cycle += 1) {
const host = new TestControllerHost()
const query = createQueryController(
host,
{
queryKey,
gcTime: 0,
queryFn: async () => cycle,
},
client,
)
host.connect()
host.update()
await waitFor(() => query().isSuccess, 4000)
const cacheQuery = client.getQueryCache().find({ queryKey })
const connectedCount = cacheQuery?.getObserversCount() ?? 0
if (connectedCount !== 1) {
throw new Error(
`observer_count_connected_invalid:${connectedCount}:cycle:${cycle}`,
)
}
host.disconnect()
query.destroy()
const disconnectedCount = cacheQuery?.getObserversCount() ?? 0
if (disconnectedCount !== 0) {
throw new Error(
`observer_count_disconnected_invalid:${disconnectedCount}:cycle:${cycle}`,
)
}
}
const elapsedMs = Date.now() - startedAt
const finalHeapMb = process.memoryUsage().heapUsed / (1024 * 1024)
const memoryGrowthMb = Number((finalHeapMb - initialHeapMb).toFixed(3))
const summary = {
measuredAt: new Date().toISOString(),
cycles,
elapsedMs,
initialHeapMb: Number(initialHeapMb.toFixed(3)),
finalHeapMb: Number(finalHeapMb.toFixed(3)),
memoryGrowthMb,
retainedObserversAfterRun:
client.getQueryCache().find({ queryKey })?.getObserversCount() ?? 0,
}
console.log(JSON.stringify(summary, null, 2))
}
run().catch((error) => {
console.error(error)
process.exit(1)
})

View File

@@ -0,0 +1,43 @@
import { readFile, readdir, stat } from 'node:fs/promises'
import path from 'node:path'
import { gzipSync } from 'node:zlib'
import { fileURLToPath } from 'node:url'
const scriptDir = path.dirname(fileURLToPath(import.meta.url))
const repoRoot = path.resolve(scriptDir, '..')
const distDir = path.join(repoRoot, 'build', 'modern')
const entryFile = path.join(distDir, 'index.js')
async function getDirSizeBytes(dirPath) {
let total = 0
const entries = await readdir(dirPath, { withFileTypes: true })
for (const entry of entries) {
const fullPath = path.join(dirPath, entry.name)
if (entry.isDirectory()) {
total += await getDirSizeBytes(fullPath)
} else if (entry.isFile()) {
total += (await stat(fullPath)).size
}
}
return total
}
async function run() {
const entry = await readFile(entryFile)
const entryGzip = gzipSync(entry)
const distBytes = await getDirSizeBytes(distDir)
const output = {
measuredAt: new Date().toISOString(),
entryJsBytes: entry.length,
entryJsGzipBytes: entryGzip.length,
distTotalBytes: distBytes,
}
console.log(JSON.stringify(output, null, 2))
}
run().catch((error) => {
console.error(error)
process.exit(1)
})