From 9516532aa5508d18d50e3792aaf2fda31bed0299 Mon Sep 17 00:00:00 2001 From: Edmond Chui <1967998+EdmondChuiHW@users.noreply.github.com> Date: Tue, 24 Sep 2024 17:23:39 +0100 Subject: [PATCH] refactor: allow custom impl of backend realod-to-profile support check --- packages/react-devtools-shared/src/backend/index.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/react-devtools-shared/src/backend/index.js b/packages/react-devtools-shared/src/backend/index.js index 86714b7f61476..0a2ec5025a40d 100644 --- a/packages/react-devtools-shared/src/backend/index.js +++ b/packages/react-devtools-shared/src/backend/index.js @@ -10,6 +10,7 @@ import Agent from './agent'; import type {DevToolsHook, RendererID, RendererInterface} from './types'; +import {isSynchronousXHRSupported} from './utils'; export type InitBackend = typeof initBackend; @@ -103,3 +104,15 @@ export function initBackend( subs.forEach(fn => fn()); }; } + +function defaultGetIsReloadAndProfileSupported(): boolean { + // Notify the frontend if the backend supports the Storage API (e.g. localStorage). + // If not, features like reload-and-profile will not work correctly and must be disabled. + let isBackendStorageAPISupported = false; + try { + localStorage.getItem('test'); + isBackendStorageAPISupported = true; + } catch (error) {} + + return isBackendStorageAPISupported && isSynchronousXHRSupported(); +}