@@ -281,6 +281,7 @@ CACHE.set(DEFAULT_THEME.colors, KEYS.colors);
281281CACHE . set ( DEFAULT_THEME . palette , KEYS . palette ) ;
282282CACHE . set ( DEFAULT_THEME . opacity , KEYS . opacity ) ;
283283
284+ /* convert `getColor` parameters to a memoization key */
284285const toKey = ( {
285286 dark,
286287 hue,
@@ -291,25 +292,37 @@ const toKey = ({
291292 transparency,
292293 variable
293294} : ColorParameters ) => {
294- let themeColorsKey = CACHE . get ( theme . colors ) ;
295+ let themeColorsKey ;
295296
296- if ( themeColorsKey === undefined ) {
297- themeColorsKey = ++ KEYS . colors ;
298- CACHE . set ( theme . colors , themeColorsKey ) ;
297+ if ( theme . colors ) {
298+ themeColorsKey = CACHE . get ( theme . colors ) ;
299+
300+ if ( themeColorsKey === undefined ) {
301+ themeColorsKey = ++ KEYS . colors ;
302+ CACHE . set ( theme . colors , themeColorsKey ) ;
303+ }
299304 }
300305
301- let themeOpacityKey = CACHE . get ( theme . opacity ) ;
306+ let themeOpacityKey ;
307+
308+ if ( theme . opacity ) {
309+ themeOpacityKey = CACHE . get ( theme . opacity ) ;
302310
303- if ( themeOpacityKey === undefined ) {
304- themeOpacityKey = ++ KEYS . opacity ;
305- CACHE . set ( theme . opacity , themeOpacityKey ) ;
311+ if ( themeOpacityKey === undefined ) {
312+ themeOpacityKey = ++ KEYS . opacity ;
313+ CACHE . set ( theme . opacity , themeOpacityKey ) ;
314+ }
306315 }
307316
308- let themePaletteKey = CACHE . get ( theme . palette ) ;
317+ let themePaletteKey ;
318+
319+ if ( theme . palette ) {
320+ themePaletteKey = CACHE . get ( theme . palette ) ;
309321
310- if ( themePaletteKey === undefined ) {
311- themePaletteKey = ++ KEYS . palette ;
312- CACHE . set ( theme . palette , themePaletteKey ) ;
322+ if ( themePaletteKey === undefined ) {
323+ themePaletteKey = ++ KEYS . palette ;
324+ CACHE . set ( theme . palette , themePaletteKey ) ;
325+ }
313326 }
314327
315328 let retVal = `{${ themeColorsKey } ,${ themePaletteKey } ,${ themeOpacityKey } }` ;
0 commit comments