reactPolling.js — react Source File
Architecture documentation for reactPolling.js, a javascript file in the react codebase. 1 imports, 1 dependents.
Entity Profile
Dependency Diagram
graph LR 8351037d_1dab_1acd_e2b9_a54883052fb1["reactPolling.js"] 5da5ec89_70b9_80cd_1b31_dcf27eddc57e["evalInInspectedWindow.js"] 8351037d_1dab_1acd_e2b9_a54883052fb1 --> 5da5ec89_70b9_80cd_1b31_dcf27eddc57e b5e42467_7633_e234_1d51_a93bfc4818c7["index.js"] b5e42467_7633_e234_1d51_a93bfc4818c7 --> 8351037d_1dab_1acd_e2b9_a54883052fb1 style 8351037d_1dab_1acd_e2b9_a54883052fb1 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import {evalInInspectedWindow} from './evalInInspectedWindow';
class CouldNotFindReactOnThePageError extends Error {
constructor() {
super("Could not find React, or it hasn't been loaded yet");
// Maintains proper stack trace for where our error was thrown (only available on V8)
if (Error.captureStackTrace) {
Error.captureStackTrace(this, CouldNotFindReactOnThePageError);
}
this.name = 'CouldNotFindReactOnThePageError';
}
}
export function startReactPolling(
onReactFound,
attemptsThreshold,
onCouldNotFindReactAfterReachingAttemptsThreshold,
) {
let status = 'idle';
function abort() {
status = 'aborted';
}
// This function will call onSuccess only if React was found and polling is not aborted, onError will be called for every other case
function checkIfReactPresentInInspectedWindow(onSuccess, onError) {
evalInInspectedWindow(
'checkIfReactPresentInInspectedWindow',
[],
(pageHasReact, exceptionInfo) => {
if (status === 'aborted') {
onError(
'Polling was aborted, user probably navigated to the other page',
);
return;
}
if (exceptionInfo) {
const {code, description, isError, isException, value} =
exceptionInfo;
if (isException) {
onError(
`Received error while checking if react has loaded: ${value}`,
);
return;
}
if (isError) {
onError(
`Received error with code ${code} while checking if react has loaded: "${description}"`,
);
return;
}
}
if (pageHasReact) {
onSuccess();
return;
}
onError(new CouldNotFindReactOnThePageError());
},
);
}
// Just a Promise wrapper around `checkIfReactPresentInInspectedWindow`
// returns a Promise, which will resolve only if React has been found on the page
function poll(attempt) {
return new Promise((resolve, reject) => {
checkIfReactPresentInInspectedWindow(resolve, reject);
}).catch(error => {
if (error instanceof CouldNotFindReactOnThePageError) {
if (attempt === attemptsThreshold) {
onCouldNotFindReactAfterReachingAttemptsThreshold();
}
// Start next attempt in 0.5s
return new Promise(r => setTimeout(r, 500)).then(() =>
poll(attempt + 1),
);
}
// Propagating every other Error
throw error;
});
}
poll(1)
.then(onReactFound)
.catch(error => {
// Log propagated errors only if polling was not aborted
// Some errors are expected when user performs in-tab navigation and `.eval()` is still being executed
if (status === 'aborted') {
return;
}
console.error(error);
});
return {abort};
}
Domain
Subdomains
Functions
Classes
Dependencies
Source
Frequently Asked Questions
What does reactPolling.js do?
reactPolling.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in reactPolling.js?
reactPolling.js defines 1 function(s): startReactPolling.
What does reactPolling.js depend on?
reactPolling.js imports 1 module(s): evalInInspectedWindow.js.
What files import reactPolling.js?
reactPolling.js is imported by 1 file(s): index.js.
Where is reactPolling.js in the architecture?
reactPolling.js is located at packages/react-devtools-extensions/src/main/reactPolling.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-extensions/src/main).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free