Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/fix-promise-mutation-10509.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@tanstack/query-core": patch
---

fix(thenable): use Object.create() to avoid Promise mutation in headless Chromium

Resolves issue where useQuery stays pending indefinitely in Puppeteer/Playwright. Headless Chromium enforces stricter Promise semantics, treating internal slots as sealed. The fix wraps the Promise with Object.create() instead of mutating it directly, preserving all Promise behavior while allowing custom properties.
19 changes: 15 additions & 4 deletions packages/query-core/src/thenable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,27 @@ export function pendingThenable<T>(): PendingThenable<T> {
let resolve: Pending<T>['resolve']
let reject: Pending<T>['reject']
// this could use `Promise.withResolvers()` in the future
const thenable = new Promise((_resolve, _reject) => {
const promise = new Promise((_resolve, _reject) => {
resolve = _resolve
reject = _reject
}) as PendingThenable<T>
})

thenable.status = 'pending'
thenable.catch(() => {
promise.catch(() => {
// prevent unhandled rejection errors
})

const thenable = Object.create(promise) as PendingThenable<T>
thenable.status = 'pending'

Comment thread
coderabbitai[bot] marked this conversation as resolved.
// Bind Promise methods so React's Suspense and other code calling .then()
// works correctly. Without binding, the native Promise implementation checks
// for internal slots on `this`, which won't exist on the wrapper object.
thenable.then = promise.then.bind(promise)
thenable.catch = promise.catch.bind(promise)
if (promise.finally) {
thenable.finally = promise.finally.bind(promise)
}

function finalize(data: Fulfilled<T> | Rejected) {
Object.assign(thenable, data)

Expand Down
Loading