Skip to content

Commit

Permalink
Only fetch news in Production mode (#3168)
Browse files Browse the repository at this point in the history
  • Loading branch information
melloware committed Aug 21, 2022
1 parent 3ca820b commit cce9003
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions pages/_app.js
Expand Up @@ -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 = {
Expand Down Expand Up @@ -64,7 +66,7 @@ export default function MyApp({ Component }) {
linkElement.remove();
cloneLinkElement.setAttribute('id', elementId);
});

linkElement.parentNode.insertBefore(cloneLinkElement, linkElement.nextSibling);
setTheme(newTheme);
}
Expand All @@ -79,5 +81,5 @@ export default function MyApp({ Component }) {
</Layout>
)
}
}

}

0 comments on commit cce9003

Please sign in to comment.