Skip to content

Commit

Permalink
fix: add browser check in media query
Browse files Browse the repository at this point in the history
  • Loading branch information
huntabyte committed Sep 29, 2024
1 parent 9878f23 commit 1a462da
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions packages/runed/src/lib/utilities/MediaQuery/MediaQuery.svelte.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { extract } from "../extract/extract.svelte.js";
import { useEventListener } from "../useEventListener/useEventListener.svelte.js";
import { IsSupported } from "../IsSupported/IsSupported.svelte.js";

Check failure on line 3 in packages/runed/src/lib/utilities/MediaQuery/MediaQuery.svelte.ts

View workflow job for this annotation

GitHub Actions / Lint

'IsSupported' is defined but never used
import type { MaybeGetter } from "$lib/internal/types.js";
import { browser } from "$lib/internal/utils/browser.js";

/**
* Takes a media query as an input and listsens for changes to it,
* Takes a media query as an input and listens for changes to it,
* holding a reactive property with its current state.
*
* @see {@link https://runed.dev/docs/utilities/media-query}
Expand Down Expand Up @@ -36,7 +38,10 @@ import type { MaybeGetter } from "$lib/internal/types.js";
export class MediaQuery {
#propQuery: MaybeGetter<string>;
#query = $derived.by(() => extract(this.#propQuery));
#mediaQueryList: MediaQueryList = $derived(window.matchMedia(this.#query));
#mediaQueryList = $derived.by(() => {
if (!browser) return null;
return window.matchMedia(this.#query);
});
#effectRegistered = 0;
#matches: boolean | undefined = $state();

Expand Down Expand Up @@ -66,6 +71,6 @@ export class MediaQuery {
});
}

return this.#matches ?? this.#mediaQueryList.matches;
return this.#matches ?? this.#mediaQueryList?.matches;
}
}

0 comments on commit 1a462da

Please sign in to comment.