@@ -5,6 +5,8 @@ import type {
55 TanStackQueryEvent ,
66 QueryActionMessage ,
77 QueryActionResult ,
8+ BulkQueryActionMessage ,
9+ BulkQueryActionResult ,
810} from "../types/messages" ;
911import type { QueryData , MutationData } from "../types/query" ;
1012
@@ -421,8 +423,67 @@ async function handleQueryAction(
421423 }
422424}
423425
426+ // Bulk query action handlers
427+ async function handleBulkQueryAction (
428+ action : BulkQueryActionMessage ,
429+ ) : Promise < BulkQueryActionResult > {
430+ const queryClient = getQueryClient ( ) ;
431+
432+ if ( ! queryClient ) {
433+ return {
434+ type : "BULK_QUERY_ACTION_RESULT" ,
435+ action : action . action ,
436+ success : false ,
437+ error : "QueryClient not found" ,
438+ } ;
439+ }
440+
441+ try {
442+ switch ( action . action ) {
443+ case "REMOVE_ALL_QUERIES" : {
444+ // Get all queries from the cache
445+ const queryCache = queryClient . getQueryCache ( ) ;
446+ const allQueries = queryCache . getAll ( ) ;
447+ const queryCount = allQueries . length ;
448+
449+ // Remove all queries
450+ queryClient . removeQueries ( ) ;
451+
452+ // Also clear artificial states for this tab
453+ window . postMessage (
454+ {
455+ source : "tanstack-query-devtools-injected" ,
456+ type : "CLEAR_ARTIFICIAL_STATES" ,
457+ } ,
458+ "*" ,
459+ ) ;
460+
461+ return {
462+ type : "BULK_QUERY_ACTION_RESULT" ,
463+ action : action . action ,
464+ success : true ,
465+ affectedCount : queryCount ,
466+ } ;
467+ }
468+
469+ default :
470+ throw new Error ( `Unknown bulk action: ${ action . action } ` ) ;
471+ }
472+ } catch ( error ) {
473+ const errorMessage = error instanceof Error ? error . message : String ( error ) ;
474+ console . error ( "TanStack Query DevTools: Bulk action failed:" , error ) ;
475+
476+ return {
477+ type : "BULK_QUERY_ACTION_RESULT" ,
478+ action : action . action ,
479+ success : false ,
480+ error : errorMessage ,
481+ } ;
482+ }
483+ }
484+
424485// Send action result to content script
425- function sendActionResult ( result : QueryActionResult ) {
486+ function sendActionResult ( result : QueryActionResult | BulkQueryActionResult ) {
426487 window . postMessage (
427488 {
428489 source : "tanstack-query-devtools-injected" ,
@@ -446,6 +507,14 @@ window.addEventListener("message", async (event) => {
446507 setTimeout ( sendQueryDataUpdate , 100 ) ;
447508 }
448509
510+ if ( event . data . type === "BULK_QUERY_ACTION" ) {
511+ const result = await handleBulkQueryAction ( event . data ) ;
512+ sendActionResult ( result ) ;
513+
514+ // Trigger query data update after bulk action
515+ setTimeout ( sendQueryDataUpdate , 100 ) ;
516+ }
517+
449518 // Handle immediate update requests from DevTools
450519 if ( event . data . type === "REQUEST_IMMEDIATE_UPDATE" ) {
451520 if ( performEnhancedDetection ( ) ) {
0 commit comments