fix tinykeys ssr import

This commit is contained in:
Nikita Galaiko 2023-04-27 08:50:26 +02:00
parent 2ec56747da
commit 23069658b0
2 changed files with 22 additions and 20 deletions

View File

@ -1,8 +1,10 @@
import { building } from '$app/environment'; import { building } from '$app/environment';
import tinykeys from 'tinykeys';
import type Events from '$lib/events'; import type Events from '$lib/events';
export default (events: ReturnType<typeof Events>) => ({ export default async (events: ReturnType<typeof Events>) =>
building
? { on: () => () => {} }
: await import('tinykeys').then(({ default: tinykeys }) => ({
on: (combo: string, callback: (event: KeyboardEvent) => void) => { on: (combo: string, callback: (event: KeyboardEvent) => void) => {
if (building) return () => {}; if (building) return () => {};
const comboContainsControlKeys = const comboContainsControlKeys =
@ -21,4 +23,4 @@ export default (events: ReturnType<typeof Events>) => ({
} }
}); });
} }
}); }));

View File

@ -46,6 +46,6 @@ export const load: LayoutLoad = wrapLoadWithSentry(async ({ fetch }) => {
posthog: Posthog(), posthog: Posthog(),
sentry: Sentry(), sentry: Sentry(),
events, events,
hotkeys: Hotkeys(events) hotkeys: await Hotkeys(events)
}; };
}); });