File tree Expand file tree Collapse file tree 1 file changed +28
-19
lines changed Expand file tree Collapse file tree 1 file changed +28
-19
lines changed Original file line number Diff line number Diff line change @@ -66,33 +66,42 @@ export const resolveBase = (base?: string): string => {
66
66
return normalize ( url . pathname )
67
67
}
68
68
69
+ let options : Options
70
+
69
71
/**
70
72
* Get options embedded in the HTML or query params.
71
73
*/
72
74
export const getOptions = < T extends Options > ( ) : T => {
73
- let options : T
74
- try {
75
- options = JSON . parse ( document . getElementById ( "coder-options" ) ! . getAttribute ( "data-settings" ) ! )
76
- } catch ( error ) {
77
- options = { } as T
78
- }
75
+ if ( ! options ) {
76
+ try {
77
+ options = JSON . parse ( document . getElementById ( "coder-options" ) ! . getAttribute ( "data-settings" ) ! )
78
+ } catch ( error ) {
79
+ console . error ( error )
80
+ options = { } as T
81
+ }
79
82
80
- // You can also pass options in stringified form to the options query
81
- // variable. Options provided here will override the ones in the options
82
- // element.
83
- const params = new URLSearchParams ( location . search )
84
- const queryOpts = params . get ( "options" )
85
- if ( queryOpts ) {
86
- options = {
87
- ...options ,
88
- ...JSON . parse ( queryOpts ) ,
83
+ // You can also pass options in stringified form to the options query
84
+ // variable. Options provided here will override the ones in the options
85
+ // element.
86
+ const params = new URLSearchParams ( location . search )
87
+ const queryOpts = params . get ( "options" )
88
+ if ( queryOpts ) {
89
+ try {
90
+ options = {
91
+ ...options ,
92
+ ...JSON . parse ( queryOpts ) ,
93
+ }
94
+ } catch ( error ) {
95
+ // Don't fail if the query parameters are malformed.
96
+ console . error ( error )
97
+ }
89
98
}
90
- }
91
99
92
- options . base = resolveBase ( options . base )
93
- options . csStaticBase = resolveBase ( options . csStaticBase )
100
+ options . base = resolveBase ( options . base )
101
+ options . csStaticBase = resolveBase ( options . csStaticBase )
102
+ }
94
103
95
- return options
104
+ return options as T
96
105
}
97
106
98
107
/**
You can’t perform that action at this time.
0 commit comments