Home / Function/ startReactPolling() — react Function Reference

startReactPolling() — react Function Reference

Architecture documentation for the startReactPolling() function in reactPolling.js from the react codebase.

Entity Profile

Dependency Diagram

graph TD
  6f2f886a_67b8_a326_ba54_02e933b8c12f["startReactPolling()"]
  8351037d_1dab_1acd_e2b9_a54883052fb1["reactPolling.js"]
  6f2f886a_67b8_a326_ba54_02e933b8c12f -->|defined in| 8351037d_1dab_1acd_e2b9_a54883052fb1
  d95f1339_0331_55af_3c59_d3c78000a3e5["mountReactDevToolsWhenReactHasLoaded()"]
  d95f1339_0331_55af_3c59_d3c78000a3e5 -->|calls| 6f2f886a_67b8_a326_ba54_02e933b8c12f
  style 6f2f886a_67b8_a326_ba54_02e933b8c12f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

packages/react-devtools-extensions/src/main/reactPolling.js lines 16–104

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') {

Domain

Subdomains

Frequently Asked Questions

What does startReactPolling() do?
startReactPolling() is a function in the react codebase, defined in packages/react-devtools-extensions/src/main/reactPolling.js.
Where is startReactPolling() defined?
startReactPolling() is defined in packages/react-devtools-extensions/src/main/reactPolling.js at line 16.
What calls startReactPolling()?
startReactPolling() is called by 1 function(s): mountReactDevToolsWhenReactHasLoaded.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free