Skip to content

Commit

Permalink
🐛 Check for window & document in code
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Apr 3, 2023
1 parent d965838 commit 14f7f8f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/routes/_layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<script>
// If `prefers-color-scheme` is not supported, fall back to light mode.
// In this case, light.css will be downloaded with `highest` priority.
if (window.matchMedia('(prefers-color-scheme: dark)').media === 'not all') {
if (typeof window !== "undefined" && typeof document !== "undefined" && "matchMedia" in window && window.matchMedia('(prefers-color-scheme: dark)').media === 'not all') {
document.documentElement.style.display = 'none';
document.head.insertAdjacentHTML(
'beforeend',
Expand Down
5 changes: 2 additions & 3 deletions src/utils/createOctokit.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const createOctokit = () => {
)
token = localStorage.getItem("personal-access-token");

const baseUrl=apiBaseUrl;
const baseUrl = apiBaseUrl;
return new Octokit({
baseUrl,
userAgent,
Expand All @@ -43,7 +43,7 @@ export const handleError = (error) => {
export const cachedResponse = async (key, fn) => {
try {
if (typeof window !== "undefined") {
if ("localStorage" in window) {
if ("localStorage" in window && typeof document !== "undefined" && "domain" in document) {
const data = localStorage.getItem(key);
if (data) {
const item = JSON.parse(data);
Expand All @@ -55,7 +55,6 @@ export const cachedResponse = async (key, fn) => {
) {
localStorage.removeItem(key);
} else {
console.log("Got cached item");
return item.data;
}
}
Expand Down

0 comments on commit 14f7f8f

Please sign in to comment.