Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip reloading a tab on service worker update if the user is in the middle of something #10996

Merged
merged 2 commits into from
Mar 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
## Next

* Fix a bug in Chrome for Android 134 and newer where the space reserved for the virtual keyboard would not be reclaimed after the keyboard is dismissed.
* When you update DIM, it will no longer reload other tabs if you have a sheet up or are on the Loadout Optimizer. DIM may fail to load some pages until you refresh, though.

## 8.63.0 <span class="changelog-date">(2025-03-16)</span>

Expand Down
4 changes: 2 additions & 2 deletions src/app/dim-ui/AutoRefresh.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { useLocation } from 'react-router';
import { isDragging$ } from '../inventory/drag-events';
import { loadingTracker } from '../shell/loading-tracker';
import { refresh$, refresh as triggerRefresh } from '../shell/refresh-events';
import { sheetsOpen } from './Sheet';
import { sheetsOpen } from './sheets-open';

const globalSettingsSelector = (state: RootState) => state.dimApi.globalSettings;

Expand Down Expand Up @@ -197,7 +197,7 @@ function useVisibilityRefresh() {
// Loadout optimizer is all about state, don't reload it
!onOptimizerPage &&
// If a sheet is up, the user is doing something. We check sheetsOpen here, because it is not reactive!
sheetsOpen <= 0
sheetsOpen.open <= 0
) {
// Sneaky updates - if DIM is hidden and needs an update, do the update.
reloadDIM();
Expand Down
11 changes: 3 additions & 8 deletions src/app/dim-ui/Sheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { AppIcon, disabledIcon } from '../shell/icons';
import ErrorBoundary from './ErrorBoundary';
import { PressTipRoot } from './PressTip';
import styles from './Sheet.m.scss';
import { sheetsOpen } from './sheets-open';
import { useFixOverscrollBehavior } from './useFixOverscrollBehavior';

/**
Expand Down Expand Up @@ -92,12 +93,6 @@ function useDisableParent(
return [effectivelyDisabled, setDisabledByChildSheet];
}

/**
* The total number of sheets that are open. Used by the sneaky updates code to
* determine if the user is in the middle of something.
*/
export let sheetsOpen = 0;

/**
* A Sheet is a UI element that comes up from the bottom of the screen,
* and can be dragged downward to dismiss
Expand Down Expand Up @@ -247,9 +242,9 @@ export default function Sheet({

// Track the total number of sheets that are open (to help prevent reloads while users are doing things)
useEffect(() => {
sheetsOpen++;
sheetsOpen.open++;
return () => {
sheetsOpen--;
sheetsOpen.open--;
};
}, []);

Expand Down
10 changes: 10 additions & 0 deletions src/app/dim-ui/sheets-open.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/**
* The total number of sheets that are open. Used by the sneaky updates code to
* determine if the user is in the middle of something.
*
* This is in a separate file from Sheet.tsx to avoid pulling in dependencies to
* tests.
*/
export const sheetsOpen = {
open: 0,
};
12 changes: 11 additions & 1 deletion src/app/register-service-worker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getClient } from '@sentry/browser';
import { toHttpStatusError } from './bungie-api/http-client';
import { sheetsOpen } from './dim-ui/sheets-open';
import { errorLog, infoLog, warnLog } from './utils/log';
import { Observable } from './utils/observable';
import { delay } from './utils/promises';
Expand Down Expand Up @@ -89,7 +90,16 @@ export default function registerServiceWorker() {
return;
}
preventDevToolsReloadLoop = true;
window.location.reload();
if (
// Loadout optimizer is all about state, don't reload it
!window.location.pathname.endsWith('/optimizer') &&
// If a sheet is up, the user is doing something. We check sheetsOpen here, because it is not reactive!
sheetsOpen.open <= 0
) {
window.location.reload();
} else {
warnLog(TAG, 'Not reloading because user is in the middle of something');
}
});
} else if ($featureFlags.debugSW) {
// At this point, everything has been precached.
Expand Down