From c329008e62fc580a75b08a4d80bf5cd826857a8d Mon Sep 17 00:00:00 2001 From: Amandeep <47453037+pbxothi@users.noreply.github.com> Date: Sun, 8 Mar 2020 00:32:44 -0500 Subject: [PATCH] Fix window is undefined Moving global window access to onMount hook for to fix "window is undefined" error when using with sapper, etc. --- src/components/UIShell/UIShell.svelte | 28 +++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/components/UIShell/UIShell.svelte b/src/components/UIShell/UIShell.svelte index 670286cc..baa27f76 100644 --- a/src/components/UIShell/UIShell.svelte +++ b/src/components/UIShell/UIShell.svelte @@ -14,20 +14,24 @@ import UIShellSideNavWrapper from './UIShellSideNav/UIShellSideNavWrapper.svelte'; import UIShellSideNavItem from './UIShellSideNav/UIShellSideNavItem.svelte'; import HamburgerMenu from './UIShellSideNav/HamburgerMenu.svelte'; - + import { onMount } from 'svelte' + let isSideNavOpen = undefined; - let winWidth = window.innerWidth; - - window.addEventListener('resize', () => { - winWidth = window.innerWidth; - - if (winWidth >= 1056) { - isSideNavOpen = true; - } else { - isSideNavOpen = false; - } - }); + let winWidth = undefined; + + onMount(() => { + winWidth = window.innerWidth + window.addEventListener('resize', () => { + winWidth = window.innerWidth; + if (winWidth >= 1056) { + isSideNavOpen = true; + } else { + isSideNavOpen = false; + } + }); + }) + $: ariaLabel = company + (uiShellAriaLabel || $$props['aria-label'] || platformName);