TagSpaces is an offline, open source, document manager with tagging support
feat: added basic handling for offline/online s3 locations
Ilian Sapundshievb57adc07e646
diff --git a/src/renderer/components/LocationView.tsx b/src/renderer/components/LocationView.tsxindex 34fe655be..19cf2bd3d 100644--- a/src/renderer/components/LocationView.tsx+++ b/src/renderer/components/LocationView.tsx@@ -43,7 +43,7 @@ import { usePerspectiveActionsContext } from '-/hooks/usePerspectiveActionsConteimport { useSelectedEntriesContext } from '-/hooks/useSelectedEntriesContext';import { TS } from '-/tagspaces.namespace';import { CommonLocation } from '-/utils/CommonLocation';-import { Box, ListItemText } from '@mui/material';+import { Badge, Box, ListItemText } from '@mui/material';import ListItem from '@mui/material/ListItem';import ListItemButton from '@mui/material/ListItemButton';import ListItemIcon from '@mui/material/ListItemIcon';@@ -53,8 +53,12 @@ import { locationType } from '@tagspaces/tagspaces-common/misc';import React, { useCallback, useMemo, useRef } from 'react';import { NativeTypes } from 'react-dnd-html5-backend';import { useTranslation } from 'react-i18next';-import { useDispatch } from 'react-redux';-import { actions as AppActions, AppDispatch } from '../reducers/app';+import { useDispatch, useSelector } from 'react-redux';+import {+ actions as AppActions,+ AppDispatch,+ isOnline as getIsOnline,+} from '../reducers/app';import DragItemTypes from './DragItemTypes';import TargetMoveFileBox from './TargetMoveFileBox';@@ -92,6 +96,10 @@ function LocationView(props: Props) {const { location, hideDrawer, workspace } = props;const subFolderLocation = findLocation(location.locationID);const isCloudLocation = subFolderLocation?.type === locationType.TYPE_CLOUD;+ const isWebDavLocation = subFolderLocation?.type === locationType.TYPE_WEBDAV;+ const isRemoteLocation = isCloudLocation || isWebDavLocation;+ const isOnline = useSelector(getIsOnline);+ const showOfflineIndicator = isRemoteLocation && !isOnline;const handleLocationIconClick = useCallback((event: React.MouseEvent<HTMLSpanElement, MouseEvent>) => {@@ -105,6 +113,10 @@ function LocationView(props: Props) {);const handleLocationClick = useCallback(() => {+ if (showOfflineIndicator) {+ showNotification(t('core:cannotOpenRemoteOffline'), 'warning', true);+ return;+ }if (currentLocation && location.locationID === currentLocation.uuid) {// the same location clickopenDirectory(currentLocationPath).then(() => {@@ -118,6 +130,9 @@ function LocationView(props: Props) {}}}, [+ showOfflineIndicator,+ showNotification,+ t,currentLocation,location,openDirectory,@@ -323,6 +338,7 @@ function LocationView(props: Props) {padding: 0,paddingRight: '15px',borderRadius: AppConfig.defaultCSSRadius,+ opacity: showOfflineIndicator ? 0.6 : 1,}}><ListItemIcon@@ -332,22 +348,31 @@ function LocationView(props: Props) {}}onClick={handleLocationIconClick}>- <Tooltip title={t('clickToExpand')}>- {isCloudLocation ? (- <CloudLocationIcon- sx={{- cursor: 'pointer',- margin: 1,- }}- />- ) : (- <LocalLocationIcon- sx={{- cursor: 'pointer',- margin: 1,- }}- />- )}+ <Tooltip+ title={+ showOfflineIndicator+ ? t('core:remoteLocationOfflineTooltip')+ : t('clickToExpand')+ }+ >+ <Badge+ color="warning"+ variant="dot"+ overlap="circular"+ invisible={!showOfflineIndicator}+ data-tid={+ showOfflineIndicator+ ? 'locationOfflineBadge_' + location.name+ : undefined+ }+ sx={{ margin: 1 }}+ >+ {isCloudLocation ? (+ <CloudLocationIcon sx={{ cursor: 'pointer' }} />+ ) : (+ <LocalLocationIcon sx={{ cursor: 'pointer' }} />+ )}+ </Badge></Tooltip></ListItemIcon><ListItemText>diff --git a/src/renderer/hooks/DirectoryContentContextProvider.tsx b/src/renderer/hooks/DirectoryContentContextProvider.tsxindex dd83a8aca..3d8e10a3e 100644--- a/src/renderer/hooks/DirectoryContentContextProvider.tsx+++ b/src/renderer/hooks/DirectoryContentContextProvider.tsx@@ -27,7 +27,11 @@ import { PerspectiveIDs } from '-/perspectives';import { defaultSettings as defaultGridSettings } from '-/perspectives/grid';import { defaultSettings as defaultListSettings } from '-/perspectives/list';import { Pro } from '-/pro';-import { actions as AppActions, AppDispatch } from '-/reducers/app';+import {+ actions as AppActions,+ AppDispatch,+ isOnline as getIsOnline,+} from '-/reducers/app';import {actions as SettingsActions,getDefaultPerspective,@@ -46,6 +50,7 @@ import {import { TS } from '-/tagspaces.namespace';import { CommonLocation } from '-/utils/CommonLocation';import { arrayBufferToDataURL, updateHistory } from '-/utils/dom';+import { isOfflineError } from '-/utils/OfflineError';import {makeCancelable,useCancelablePerLocation,@@ -247,6 +252,7 @@ export const DirectoryContentContextProvider = ({const showUnixHiddenEntries = useSelector(getShowUnixHiddenEntries);const defaultPerspective = useSelector(getDefaultPerspective);const tagDelimiter: string = useSelector(getTagDelimiter);+ const isOnline = useSelector(getIsOnline);const currentDirectoryEntries = useRef<TS.FileSystemEntry[]>([]);const { signal, abort, cancelAbort } =@@ -356,6 +362,27 @@ export const DirectoryContentContextProvider = ({};}, [currentLocation]);+ // When the device transitions to offline, abort any in-flight directory+ // listing so the user doesn't sit through the AWS SDK timeout. Per the V1+ // plan, only listings subscribe to this signal — in-flight saves keep+ // running (S3 PutObject is atomic; cancelling defensively could discard+ // work that the SDK's internal retry would have committed).+ const wasOnline = useRef<boolean>(isOnline);+ useEffect(() => {+ if (wasOnline.current && !isOnline) {+ // Only abort when the current location is remote — local listings+ // don't care about network state.+ if (+ currentLocation &&+ (currentLocation.haveObjectStoreSupport() ||+ currentLocation.haveWebDavSupport())+ ) {+ abort();+ }+ }+ wasOnline.current = isOnline;+ }, [isOnline, currentLocation, abort]);+useEffect(() => {if (!firstRender && metaActions && metaActions.length > 0) {for (const action of metaActions) {@@ -1031,6 +1058,15 @@ export const DirectoryContentContextProvider = ({.catch((err) => {if (err.name === 'AbortError') {console.log('cancelableFetch was canceled');+ // If we aborted because the device went offline, surface that+ // explicitly — otherwise the user just sees a silent empty list.+ if (typeof navigator !== 'undefined' && !navigator.onLine) {+ showNotification(+ t('core:offlineLocationUnavailable'),+ 'warning',+ true,+ );+ }} else {console.error('Other error:', err);}@@ -1143,6 +1179,13 @@ export const DirectoryContentContextProvider = ({console.log('Error loading directory: ', error);//hideNotifications();+ // OfflineError: don't close locations — they'll be usable again when the+ // device reconnects. Show a clear offline-specific message instead.+ if (isOfflineError(error)) {+ showNotification(t('core:offlineLocationUnavailable'), 'warning', true);+ return [];+ }+showNotification(t('core:errorLoadingFolder') + ': ' + error.message,'warning',diff --git a/src/renderer/locales/en/core.json b/src/renderer/locales/en/core.jsonindex 97bb619c6..7883ff3c5 100644--- a/src/renderer/locales/en/core.json+++ b/src/renderer/locales/en/core.json@@ -455,6 +455,9 @@"locationType": "Type","firstOpenaFolder": "Please first open a folder!","errorLoadingFolder": "Error loading folder",+ "cannotOpenRemoteOffline": "Cannot open this remote location while offline",+ "offlineLocationUnavailable": "Network is offline. Remote location load was canceled.",+ "remoteLocationOfflineTooltip": "Unavailable while offline","fileCreateSuccessfully": "File create successfully","errorCreatingFile": "Error creating file","connectedtoObjectStore": "Connected to object storage",diff --git a/src/renderer/reducers/app.ts b/src/renderer/reducers/app.tsindex e6724135b..c2b734e2f 100644--- a/src/renderer/reducers/app.ts+++ b/src/renderer/reducers/app.ts@@ -29,6 +29,7 @@ import {setLanguage,} from '-/services/utils-io';import { getURLParameter } from '-/utils/dom';+import { deriveInitialOnline } from '-/utils/OfflineError';import { cleanFrontDirSeparator } from '@tagspaces/tagspaces-common/paths';import i18n from '../services/i18n';@@ -78,7 +79,7 @@ if (AppConfig.ExtDefaultVerticalPanel === 'none') {export const initialState = {error: null,loggedIn: false,- isOnline: false,+ isOnline: deriveInitialOnline(),lastError: '',progress: [],isUpdateInProgress: false,diff --git a/src/renderer/utils/CommonLocation.ts b/src/renderer/utils/CommonLocation.tsindex 09046b880..e9429cc5f 100644--- a/src/renderer/utils/CommonLocation.ts+++ b/src/renderer/utils/CommonLocation.ts@@ -18,6 +18,7 @@ import { getUuid, loadJSONString } from '@tagspaces/tagspaces-common/utils-io';import { Pro } from '-/pro';import { getFulfilledResults, getMimeType } from '-/services/utils-io';import { TS } from '-/tagspaces.namespace';+import { offlineRejectionIfRemote } from '-/utils/OfflineError';import * as cordovaIO from '@tagspaces/tagspaces-common-cordova';// Capacitor IO is loaded dynamically to avoid breaking Electron/web builds@@ -383,6 +384,8 @@ export class CommonLocation implements TS.Location {ignorePatterns: Array<string> = [],resultsLimit: any = {},): Promise<Array<any>> => {+ const offlineReject = offlineRejectionIfRemote(this, 'list directory');+ if (offlineReject) return offlineReject;if (this.ioAPI) {if (this.haveObjectStoreSupport()) {return this.ioAPI.listDirectoryPromise(@@ -418,6 +421,8 @@ export class CommonLocation implements TS.Location {};listMetaDirectoryPromise = (param: any): Promise<Array<any>> => {+ const offlineReject = offlineRejectionIfRemote(this, 'list metadata');+ if (offlineReject) return offlineReject;if (this.ioAPI) {if (this.haveObjectStoreSupport()) {return this.ioAPI.listMetaDirectoryPromise({@@ -439,6 +444,8 @@ export class CommonLocation implements TS.Location {};checkFileEncryptedPromise = (path: string): Promise<boolean> => {+ const offlineReject = offlineRejectionIfRemote(this, 'check encryption');+ if (offlineReject) return offlineReject;if (this.ioAPI) {if (this.haveObjectStoreSupport() && this.encryptionKey) {return this.ioAPI@@ -462,6 +469,8 @@ export class CommonLocation implements TS.Location {useEncryption: boolean = true,extractLinks: boolean = false,): Promise<any> => {+ const offlineReject = offlineRejectionIfRemote(this, 'get properties');+ if (offlineReject) return offlineReject;if (this.ioAPI) {if (this.haveObjectStoreSupport()) {return this.ioAPI.getPropertiesPromise({@@ -487,6 +496,8 @@ export class CommonLocation implements TS.Location {if (file === undefined) {return Promise.resolve(false);}+ const offlineReject = offlineRejectionIfRemote(this, 'check file');+ if (offlineReject) return offlineReject;if (this.ioAPI) {if (this.haveObjectStoreSupport()) {return this.ioAPI.isFileExist({@@ -509,6 +520,8 @@ export class CommonLocation implements TS.Location {};checkDirExist = (dir: string): Promise<boolean> => {+ const offlineReject = offlineRejectionIfRemote(this, 'check directory');+ if (offlineReject) return offlineReject;if (this.ioAPI) {if (this.haveObjectStoreSupport()) {return this.ioAPI@@ -554,6 +567,8 @@ export class CommonLocation implements TS.Location {};generateURLforPath = async (path, expirationInSeconds) => {+ const offlineReject = offlineRejectionIfRemote(this, 'sign URL');+ if (offlineReject) return offlineReject;let url;if (this.ioAPI) {if (this.haveObjectStoreSupport()) {@@ -612,6 +627,8 @@ export class CommonLocation implements TS.Location {if (this.isReadOnly) {return Promise.reject(new Error('read only Location'));}+ const offlineReject = offlineRejectionIfRemote(this, 'create directory');+ if (offlineReject) return offlineReject;if (this.ioAPI) {if (this.haveObjectStoreSupport()) {return this.ioAPI.createDirectoryPromise({@@ -637,6 +654,10 @@ export class CommonLocation implements TS.Location {if (this.isReadOnly) {return Promise.reject(new Error('read only Location'));}+ const offlineReject = offlineRejectionIfRemote(this, 'copy file');+ if (offlineReject) {+ return offlineReject;+ }if (this.ioAPI) {if (this.haveObjectStoreSupport()) {return this.ioAPI.copyFilePromise(@@ -671,6 +692,10 @@ export class CommonLocation implements TS.Location {if (this.isReadOnly) {return Promise.reject(new Error('read only Location'));}+ const offlineReject = offlineRejectionIfRemote(this, 'rename file');+ if (offlineReject) {+ return offlineReject;+ }if (this.ioAPI) {if (this.haveObjectStoreSupport()) {return this.ioAPI.renameFilePromise(@@ -704,6 +729,8 @@ export class CommonLocation implements TS.Location {if (this.isReadOnly) {return Promise.reject(new Error('read only Location'));}+ const offlineReject = offlineRejectionIfRemote(this, 'rename directory');+ if (offlineReject) return offlineReject;if (this.ioAPI) {if (this.haveObjectStoreSupport()) {return this.ioAPI.renameDirectoryPromise(@@ -735,6 +762,8 @@ export class CommonLocation implements TS.Location {if (this.isReadOnly) {return Promise.reject(new Error('read only Location'));}+ const offlineReject = offlineRejectionIfRemote(this, 'copy directory');+ if (offlineReject) return offlineReject;if (this.ioAPI) {if (this.haveObjectStoreSupport()) {return this.ioAPI.copyDirectoryPromise(@@ -768,6 +797,8 @@ export class CommonLocation implements TS.Location {if (this.isReadOnly) {return Promise.reject(new Error('read only Location'));}+ const offlineReject = offlineRejectionIfRemote(this, 'move directory');+ if (offlineReject) return offlineReject;if (this.ioAPI) {if (this.haveObjectStoreSupport()) {return this.ioAPI.moveDirectoryPromise(@@ -801,6 +832,8 @@ export class CommonLocation implements TS.Location {if (this.isReadOnly) {return Promise.reject(new Error('read only Location'));}+ const offlineReject = offlineRejectionIfRemote(this, 'save file');+ if (offlineReject) return offlineReject;if (this.ioAPI) {if (this.haveObjectStoreSupport()) {return this.ioAPI.saveFilePromise(@@ -834,6 +867,8 @@ export class CommonLocation implements TS.Location {if (this.isReadOnly) {return Promise.reject(new Error('read only Location'));}+ const offlineReject = offlineRejectionIfRemote(this, 'save file');+ if (offlineReject) return offlineReject;if (this.ioAPI) {if (this.haveObjectStoreSupport()) {return this.ioAPI.saveTextFilePromise(@@ -871,6 +906,8 @@ export class CommonLocation implements TS.Location {if (this.isReadOnly) {return Promise.reject(new Error('read only Location'));}+ const offlineReject = offlineRejectionIfRemote(this, 'save file');+ if (offlineReject) return offlineReject;if (this.ioAPI) {if (this.haveObjectStoreSupport()) {return this.ioAPI.saveBinaryFilePromise(@@ -919,6 +956,8 @@ export class CommonLocation implements TS.Location {if (this.isReadOnly) {return Promise.reject(new Error('read only Location'));}+ const offlineReject = offlineRejectionIfRemote(this, 'delete file');+ if (offlineReject) return offlineReject;if (this.ioAPI) {if (this.haveObjectStoreSupport()) {return this.ioAPI.deleteFilePromise({@@ -942,6 +981,8 @@ export class CommonLocation implements TS.Location {if (this.isReadOnly) {return Promise.reject(new Error('read only Location'));}+ const offlineReject = offlineRejectionIfRemote(this, 'delete directory');+ if (offlineReject) return offlineReject;if (this.ioAPI) {if (this.haveObjectStoreSupport()) {return this.ioAPI.deleteDirectoryPromise({@@ -987,6 +1028,8 @@ export class CommonLocation implements TS.Location {isPreview?: boolean,useEncryption: boolean = true,): Promise<string> => {+ const offlineReject = offlineRejectionIfRemote(this, 'load file');+ if (offlineReject) return offlineReject;let filePath = this.getPath(param);try {filePath = decodeURIComponent(filePath);@@ -1033,6 +1076,8 @@ export class CommonLocation implements TS.Location {};getFileContentPromise = (param: any, type?: string): Promise<any> => {+ const offlineReject = offlineRejectionIfRemote(this, 'load file content');+ if (offlineReject) return offlineReject;const filePath = this.getPath(param);if (this.ioAPI) {if (this.haveObjectStoreSupport()) {diff --git a/src/renderer/utils/OfflineError.ts b/src/renderer/utils/OfflineError.tsnew file mode 100644index 000000000..30f951105--- /dev/null+++ b/src/renderer/utils/OfflineError.ts@@ -0,0 +1,77 @@+/**+ * TagSpaces - universal file and folder organizer+ * Copyright (C) 2026-present TagSpaces GmbH+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License (version 3) as+ * published by the Free Software Foundation.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ *+ */++// Thrown when a remote (S3 / WebDAV) operation is attempted while+// navigator.onLine is false. Detected by name to follow the same convention+// as the AbortError handling already in DirectoryContentContextProvider.+export class OfflineError extends Error {+ constructor(message = 'Network is offline') {+ super(message);+ this.name = 'OfflineError';+ }+}++export function isOfflineError(err: unknown): boolean {+ return (+ typeof err === 'object' &&+ err !== null &&+ 'name' in err &&+ (err as { name: string }).name === 'OfflineError'+ );+}++/**+ * Initial online state. Reads navigator.onLine when available so that an app+ * launched while offline doesn't start in a falsely-online state. The window+ * 'online'/'offline' events (wired in services/onlineListener.ts) only fire+ * on transitions, so without this the boot value would lag reality.+ *+ * Falls back to `true` in non-browser contexts (Node/SSR) — being optimistic+ * is correct because remote operations will surface their own errors if the+ * environment can't reach the network.+ */+export function deriveInitialOnline(): boolean {+ return typeof navigator !== 'undefined' ? navigator.onLine : true;+}++export interface RemoteCapableLocation {+ haveObjectStoreSupport: () => boolean;+ haveWebDavSupport: () => boolean;+ name: string;+}++/**+ * Returns a rejected Promise<OfflineError> when `loc` is a remote (S3/WebDAV)+ * location and navigator.onLine is false. Returns null otherwise.+ *+ * Free function (not a class method) so adding offline checks doesn't change+ * the structural shape of CommonLocation — sites like dialogs spread location+ * objects and TS would otherwise complain about a missing class member.+ */+export function offlineRejectionIfRemote(+ loc: RemoteCapableLocation,+ op: string,+): Promise<never> | null {+ if (typeof navigator === 'undefined' || navigator.onLine) return null;+ if (!loc.haveObjectStoreSupport() && !loc.haveWebDavSupport()) return null;+ return Promise.reject(+ new OfflineError(+ `Cannot ${op} on remote location "${loc.name}" while offline`,+ ),+ );+}diff --git a/tests/unit/offline.test.js b/tests/unit/offline.test.jsnew file mode 100644index 000000000..1a6590136--- /dev/null+++ b/tests/unit/offline.test.js@@ -0,0 +1,152 @@+import { afterEach, beforeEach, describe, expect, test } from '@playwright/test';++import {+ deriveInitialOnline,+ isOfflineError,+ OfflineError,+ offlineRejectionIfRemote,+} from '-/utils/OfflineError';++// In Node 21+ `globalThis.navigator` is exposed as a getter-only property,+// so plain `globalThis.navigator = …` throws. Use defineProperty to fully+// replace the descriptor for each test, then restore the original.+let originalDescriptor;+function setNavigator(value) {+ if (value === undefined) {+ delete globalThis.navigator;+ return;+ }+ Object.defineProperty(globalThis, 'navigator', {+ value,+ configurable: true,+ writable: true,+ });+}++beforeEach(() => {+ originalDescriptor = Object.getOwnPropertyDescriptor(globalThis, 'navigator');+});++afterEach(() => {+ delete globalThis.navigator;+ if (originalDescriptor) {+ Object.defineProperty(globalThis, 'navigator', originalDescriptor);+ }+});++describe('OfflineError', () => {+ test('has name "OfflineError" and is an Error', () => {+ const err = new OfflineError('boom');+ expect(err).toBeInstanceOf(Error);+ expect(err.name).toBe('OfflineError');+ expect(err.message).toBe('boom');+ });++ test('default message when none supplied', () => {+ const err = new OfflineError();+ expect(err.message).toBe('Network is offline');+ });+});++describe('isOfflineError', () => {+ test('true for OfflineError instances', () => {+ expect(isOfflineError(new OfflineError())).toBe(true);+ });++ test('true for any object whose name field is "OfflineError"', () => {+ // Catches the case where the error crosses a serialization boundary+ // and only the name is preserved (e.g. structured-clone via IPC).+ expect(isOfflineError({ name: 'OfflineError', message: 'x' })).toBe(true);+ });++ test('false for AbortError, plain Error, and non-objects', () => {+ const abort = new Error('aborted');+ abort.name = 'AbortError';+ expect(isOfflineError(abort)).toBe(false);+ expect(isOfflineError(new Error('boom'))).toBe(false);+ expect(isOfflineError(null)).toBe(false);+ expect(isOfflineError(undefined)).toBe(false);+ expect(isOfflineError('OfflineError')).toBe(false);+ });+});++describe('offlineRejectionIfRemote', () => {+ const remoteCloud = {+ name: 'my-bucket',+ haveObjectStoreSupport: () => true,+ haveWebDavSupport: () => false,+ };+ const remoteWebDav = {+ name: 'my-webdav',+ haveObjectStoreSupport: () => false,+ haveWebDavSupport: () => true,+ };+ const local = {+ name: 'local-folder',+ haveObjectStoreSupport: () => false,+ haveWebDavSupport: () => false,+ };++ test('returns null when navigator is undefined (Node/SSR)', () => {+ setNavigator(undefined);+ expect(offlineRejectionIfRemote(remoteCloud, 'list')).toBeNull();+ });++ test('returns null when online (regardless of location type)', () => {+ setNavigator({ onLine: true });+ expect(offlineRejectionIfRemote(remoteCloud, 'list')).toBeNull();+ expect(offlineRejectionIfRemote(remoteWebDav, 'list')).toBeNull();+ expect(offlineRejectionIfRemote(local, 'list')).toBeNull();+ });++ test('returns null for local locations even when offline', () => {+ setNavigator({ onLine: false });+ expect(offlineRejectionIfRemote(local, 'list')).toBeNull();+ });++ test('rejects with OfflineError for S3 (TYPE_CLOUD) when offline', async () => {+ setNavigator({ onLine: false });+ const result = offlineRejectionIfRemote(remoteCloud, 'list directory');+ expect(result).not.toBeNull();+ let caught;+ try {+ await result;+ } catch (e) {+ caught = e;+ }+ expect(isOfflineError(caught)).toBe(true);+ // The op + location name should appear in the message so that surfaced+ // toasts can attribute the failure if needed.+ expect(caught.message).toContain('list directory');+ expect(caught.message).toContain('my-bucket');+ });++ test('rejects with OfflineError for WebDAV when offline', async () => {+ setNavigator({ onLine: false });+ const result = offlineRejectionIfRemote(remoteWebDav, 'save file');+ let caught;+ try {+ await result;+ } catch (e) {+ caught = e;+ }+ expect(isOfflineError(caught)).toBe(true);+ });+});++describe('deriveInitialOnline', () => {+ test('reflects navigator.onLine when navigator exists', () => {+ setNavigator({ onLine: true });+ expect(deriveInitialOnline()).toBe(true);+ setNavigator({ onLine: false });+ expect(deriveInitialOnline()).toBe(false);+ });++ test('falls back to true when navigator is undefined (SSR/Node)', () => {+ // Without this fallback an app launched in a non-browser context (or+ // a renderer that hasn't initialized navigator yet) would start in a+ // falsely-offline state and block all remote operations.+ setNavigator(undefined);+ expect(deriveInitialOnline()).toBe(true);+ });+});