File tree Expand file tree Collapse file tree 2 files changed +16
-3
lines changed
packages/svelte-query/src Expand file tree Collapse file tree 2 files changed +16
-3
lines changed Original file line number Diff line number Diff line change 1+ import { describe , expect , it } from 'vitest'
2+ import { getIsRestoringContext } from '../context'
3+
4+ describe ( 'getIsRestoringContext' , ( ) => {
5+ it ( 'Should not throw when called outside of a component' , async ( ) => {
6+ expect ( ( ) => getIsRestoringContext ( ) ) . to . not . throw ( )
7+ } )
8+ } )
Original file line number Diff line number Diff line change @@ -26,9 +26,14 @@ const _isRestoringContextKey = '$$_isRestoring'
2626
2727/** Retrieves a `isRestoring` from Svelte's context */
2828export const getIsRestoringContext = ( ) : Readable < boolean > => {
29- const isRestoring = getContext ( _isRestoringContextKey )
30- if ( ! isRestoring ) return readable ( false )
31- return isRestoring as Readable < boolean >
29+ try {
30+ const isRestoring = getContext < Readable < boolean > | undefined > (
31+ _isRestoringContextKey ,
32+ )
33+ return isRestoring ? isRestoring : readable ( false )
34+ } catch ( error ) {
35+ return readable ( false )
36+ }
3237}
3338
3439/** Sets a `isRestoring` on Svelte's context */
You can’t perform that action at this time.
0 commit comments