From cce9003716425437a9f96f1a8d7ff61793d69afb Mon Sep 17 00:00:00 2001 From: Melloware Date: Sun, 21 Aug 2022 12:37:05 -0400 Subject: [PATCH] Only fetch news in Production mode (#3168) --- pages/_app.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/pages/_app.js b/pages/_app.js index 4e439428ff..c6011c9985 100644 --- a/pages/_app.js +++ b/pages/_app.js @@ -15,22 +15,24 @@ export default function MyApp({ Component }) { const announcement = useRef(null); useEffect(() => { - fetchNews().then(data => { - if (data) { - announcement.current = data; - - const itemString = localStorage.getItem(storageKey); - if (itemString) { - const item = JSON.parse(itemString); - if (item.hiddenNews && item.hiddenNews !== data.id) { + if (process.env.NODE_ENV === 'production') { + fetchNews().then(data => { + if (data) { + announcement.current = data; + + const itemString = localStorage.getItem(storageKey); + if (itemString) { + const item = JSON.parse(itemString); + if (item.hiddenNews && item.hiddenNews !== data.id) { + setNewsActive(true); + } + } + else { setNewsActive(true); } } - else { - setNewsActive(true); - } - } - }); + }); + } }, []); const props = { @@ -64,7 +66,7 @@ export default function MyApp({ Component }) { linkElement.remove(); cloneLinkElement.setAttribute('id', elementId); }); - + linkElement.parentNode.insertBefore(cloneLinkElement, linkElement.nextSibling); setTheme(newTheme); } @@ -79,5 +81,5 @@ export default function MyApp({ Component }) { ) } - -} \ No newline at end of file + +}