@@ -15,6 +15,7 @@ export type FlashOptions = Partial<{
15
15
type FlashContext = {
16
16
store : Writable < App . PageData [ 'flash' ] > ;
17
17
options : FlashOptions ;
18
+ optionHash : string ;
18
19
} ;
19
20
20
21
const flashStores = new WeakMap < Readable < Page > , FlashContext > ( ) ;
@@ -41,22 +42,7 @@ export function initFlash(
41
42
42
43
function _initFlash ( page : Readable < Page > , options ?: FlashOptions ) : Writable < App . PageData [ 'flash' ] > {
43
44
const flashStore = flashStores . get ( page ) ;
44
-
45
- if ( flashStore && ! options ) {
46
- /*
47
- console.log(
48
- {
49
- hasStore: true,
50
- route: get(page).route.id,
51
- customOptions: flashStore.options !== defaultOptions
52
- },
53
- flashStore.options
54
- );
55
- */
56
- return flashStore . store ;
57
- } else if ( flashStore && options && flashStore . options !== options ) {
58
- throw new Error ( 'getFlash options can only be set once, at a top-level component.' ) ;
59
- }
45
+ if ( flashStore && ! options ) return flashStore . store ;
60
46
61
47
const currentOptions : FlashOptions = options
62
48
? {
@@ -69,19 +55,12 @@ function _initFlash(page: Readable<Page>, options?: FlashOptions): Writable<App.
69
55
}
70
56
: defaultOptions ;
71
57
58
+ if ( flashStore && options && serializeOptions ( currentOptions ) !== flashStore . optionHash ) {
59
+ throw new Error ( 'getFlash options can only be set once, at a top-level component.' ) ;
60
+ }
61
+
72
62
const store = writable < App . PageData [ 'flash' ] > ( ) ;
73
- const context = { store, options : currentOptions } ;
74
-
75
- /*
76
- console.log(
77
- {
78
- hasStore: false,
79
- route: get(page).route.id,
80
- customOptions: context.options !== defaultOptions
81
- },
82
- context.options
83
- );
84
- */
63
+ const context = { store, options : currentOptions , optionHash : serializeOptions ( currentOptions ) } ;
85
64
86
65
flashStores . set ( page , context ) ;
87
66
clearCookieAndUpdateIfNewData ( context , get ( page ) . data . flash ) ;
@@ -145,6 +124,10 @@ function _initFlash(page: Readable<Page>, options?: FlashOptions): Writable<App.
145
124
return store ;
146
125
}
147
126
127
+ function serializeOptions ( opts : FlashOptions ) {
128
+ return JSON . stringify ( opts ) ;
129
+ }
130
+
148
131
/**
149
132
* Retrieves the flash message store for display or modification.
150
133
* @param page Page store, imported from `$app/stores`.
0 commit comments