From 4d36c271adad7bb2432a531cfb875b34dd4cad91 Mon Sep 17 00:00:00 2001 From: Raashish Aggarwal <94279692+raashish1601@users.noreply.github.com> Date: Sat, 30 May 2026 14:40:50 +0530 Subject: [PATCH] fix(query-devtools): set goober nonce before style creation --- packages/query-devtools/src/__tests__/utils.test.ts | 7 +++++++ packages/query-devtools/src/utils.tsx | 2 ++ 2 files changed, 9 insertions(+) diff --git a/packages/query-devtools/src/__tests__/utils.test.ts b/packages/query-devtools/src/__tests__/utils.test.ts index 511553e2bb..065337dc8c 100644 --- a/packages/query-devtools/src/__tests__/utils.test.ts +++ b/packages/query-devtools/src/__tests__/utils.test.ts @@ -982,6 +982,7 @@ describe('Utils tests', () => { describe('setupStyleSheet', () => { afterEach(() => { document.head.querySelector('#_goober')?.remove() + ;(window as { __nonce__?: string }).__nonce__ = undefined }) it('should not insert any style tag when "nonce" is missing', () => { @@ -1012,6 +1013,12 @@ describe('Utils tests', () => { ).toBe('test-nonce') }) + it('should set the global "__nonce__" on window', () => { + setupStyleSheet('test-nonce') + + expect((window as { __nonce__?: string }).__nonce__).toBe('test-nonce') + }) + it('should not insert a duplicate style tag when "document.head" already has one', () => { setupStyleSheet('first-nonce') setupStyleSheet('second-nonce') diff --git a/packages/query-devtools/src/utils.tsx b/packages/query-devtools/src/utils.tsx index 5306f2cf5f..58b104539d 100644 --- a/packages/query-devtools/src/utils.tsx +++ b/packages/query-devtools/src/utils.tsx @@ -306,6 +306,8 @@ export const deleteNestedDataByPath = ( // Adds a nonce to the style tag if needed export const setupStyleSheet = (nonce?: string, target?: ShadowRoot) => { if (!nonce) return + ;(window as { __nonce__?: string }).__nonce__ = nonce + const styleExists = document.querySelector('#_goober') || target?.querySelector('#_goober')