Skip to content

Commit

Permalink
feat: make service worker optional and disabled by default
Browse files Browse the repository at this point in the history
  • Loading branch information
vpicone committed Sep 21, 2020
1 parent ab59d61 commit e2db595
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
7 changes: 5 additions & 2 deletions packages/gatsby-theme-carbon/gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ module.exports = (themeOptions) => {
gatsbyRemarkPlugins = [],
remarkPlugins = [],
gatsbyPluginSharpOptions = {},
offline = true,
isServiceWorkerEnabled = false,
} = themeOptions;

const optionalPlugins = [offline ? `gatsby-plugin-offline` : undefined];
const optionalPlugins = [
isServiceWorkerEnabled ? `gatsby-plugin-offline` : undefined,
];

if (mediumAccount) {
optionalPlugins.push({
Expand Down Expand Up @@ -60,6 +62,7 @@ module.exports = (themeOptions) => {
siteMetadata: {
isSearchEnabled,
navigationStyle,
isServiceWorkerEnabled,
title: 'Gatsby Theme Carbon',
description:
'Add a description by supplying it to siteMetadata in your gatsby-config.js file.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,23 @@ import styles from './LeftNav.module.scss';

import NavContext from '../../util/context/NavContext';
import usePathprefix from '../../util/hooks/usePathprefix';
import useMetadata from '../../util/hooks/useMetadata';

export const SERVICE_WORKER_UPDATE_FOUND = 'myAppServiceWorkerUpdateFound';

const LeftNavItem = (props) => {
const { items, category, hasDivider } = props;
const { toggleNavState } = useContext(NavContext);
const { isServiceWorkerEnabled } = useMetadata();
const isOnline = useNetwork();

const handleClick = (event, to) => {
toggleNavState('leftNavIsOpen', 'close');
if (isOnline && window[SERVICE_WORKER_UPDATE_FOUND] === true) {
event.preventDefault();
window.location.href = to;
if (isServiceWorkerEnabled) {
if (isOnline && window[SERVICE_WORKER_UPDATE_FOUND] === true) {
event.preventDefault();
window.location.href = to;
}
}
};

Expand Down

0 comments on commit e2db595

Please sign in to comment.