@@ -7,7 +7,7 @@ import { ThemeProvider as EmotionThemeProvider } from "@emotion/react";
7
7
import { DecoratorHelpers } from "@storybook/addon-themes" ;
8
8
import { withRouter } from "storybook-addon-remix-react-router" ;
9
9
import { StrictMode } from "react" ;
10
- import { QueryClient , QueryClientProvider } from "react-query" ;
10
+ import { parseQueryArgs , QueryClient , QueryClientProvider } from "react-query" ;
11
11
import { HelmetProvider } from "react-helmet-async" ;
12
12
import themes from "theme" ;
13
13
import "theme/globalFonts" ;
@@ -93,7 +93,18 @@ function withQuery(Story, { parameters }) {
93
93
94
94
if ( parameters . queries ) {
95
95
parameters . queries . forEach ( ( query ) => {
96
- queryClient . setQueryData ( query . key , query . data ) ;
96
+ if ( query . data instanceof Error ) {
97
+ // This is copied from setQueryData() but sets the error.
98
+ const cache = queryClient . getQueryCache ( ) ;
99
+ const parsedOptions = parseQueryArgs ( query . key )
100
+ const defaultedOptions = queryClient . defaultQueryOptions ( parsedOptions )
101
+ const cachedQuery = cache . build ( queryClient , defaultedOptions ) ;
102
+ // Set manual data so react-query will not try to refetch.
103
+ cachedQuery . setData ( undefined , { manual : true } ) ;
104
+ cachedQuery . setState ( { error : query . data } ) ;
105
+ } else {
106
+ queryClient . setQueryData ( query . key , query . data ) ;
107
+ }
97
108
} ) ;
98
109
}
99
110
0 commit comments