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 1/3] 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);
From ee27d7b8cd9d12688a173f2c4378bf75bf841a90 Mon Sep 17 00:00:00 2001
From: Amandeep <47453037+pbxothi@users.noreply.github.com>
Date: Sun, 8 Mar 2020 20:00:45 -0400
Subject: [PATCH 2/3] Use svelte:window to bind winWidth to improve SSR
Removed handler
---
src/components/UIShell/UIShell.svelte | 16 +++-------------
1 file changed, 3 insertions(+), 13 deletions(-)
diff --git a/src/components/UIShell/UIShell.svelte b/src/components/UIShell/UIShell.svelte
index baa27f76..1cca4d4d 100644
--- a/src/components/UIShell/UIShell.svelte
+++ b/src/components/UIShell/UIShell.svelte
@@ -18,23 +18,13 @@
let isSideNavOpen = undefined;
let winWidth = undefined;
-
- onMount(() => {
- winWidth = window.innerWidth
- window.addEventListener('resize', () => {
- winWidth = window.innerWidth;
+ $: isSideNavOpen = winWidth >= 1056
- if (winWidth >= 1056) {
- isSideNavOpen = true;
- } else {
- isSideNavOpen = false;
- }
- });
- })
-
$: ariaLabel = company + (uiShellAriaLabel || $$props['aria-label'] || platformName);
+
+