loadSourceAndMetadata.js — react Source File
Architecture documentation for loadSourceAndMetadata.js, a javascript file in the react codebase. 8 imports, 2 dependents.
Entity Profile
Dependency Diagram
graph LR c387cbce_0129_194c_6a44_3db01fd37956["loadSourceAndMetadata.js"] ff1125e1_0809_ce84_8615_e747ab0e6203["SourceMapUtils.js"] c387cbce_0129_194c_6a44_3db01fd37956 --> ff1125e1_0809_ce84_8615_e747ab0e6203 fd9af6fe_0d02_805e_69cc_273e539a9202["sourceMapIncludesSource"] c387cbce_0129_194c_6a44_3db01fd37956 --> fd9af6fe_0d02_805e_69cc_273e539a9202 1cf4efe1_9da2_a991_9522_cf313b27188c["SourceMapTypes.js"] c387cbce_0129_194c_6a44_3db01fd37956 --> 1cf4efe1_9da2_a991_9522_cf313b27188c 55d27179_f566_db64_927b_e95655abee00["constants"] c387cbce_0129_194c_6a44_3db01fd37956 --> 55d27179_f566_db64_927b_e95655abee00 2aea215d_7dea_32ff_b58a_e3e98c264b47["hookSourceLocation"] c387cbce_0129_194c_6a44_3db01fd37956 --> 2aea215d_7dea_32ff_b58a_e3e98c264b47 7e1e25cd_0db6_762f_27ad_866e33149c52["PerformanceLoggingUtils"] c387cbce_0129_194c_6a44_3db01fd37956 --> 7e1e25cd_0db6_762f_27ad_866e33149c52 741f125f_8d71_2134_c016_a18fb8f60d66["ReactDebugHooks"] c387cbce_0129_194c_6a44_3db01fd37956 --> 741f125f_8d71_2134_c016_a18fb8f60d66 2e5d5bab_71fd_5a80_3fa3_895dcaab6301["FetchFileWithCachingContext"] c387cbce_0129_194c_6a44_3db01fd37956 --> 2e5d5bab_71fd_5a80_3fa3_895dcaab6301 1fe61eb6_8e55_40d8_4d18_db1927e3d6fd["index.js"] 1fe61eb6_8e55_40d8_4d18_db1927e3d6fd --> c387cbce_0129_194c_6a44_3db01fd37956 76da1f28_5fe1_2c37_5657_67756acc6f55["parseSourceAndMetadata.js"] 76da1f28_5fe1_2c37_5657_67756acc6f55 --> c387cbce_0129_194c_6a44_3db01fd37956 style c387cbce_0129_194c_6a44_3db01fd37956 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
// Parsing source and source maps is done in a Web Worker
// because parsing is CPU intensive and should not block the UI thread.
//
// Fetching source and source map files is intentionally done on the UI thread
// so that loaded source files can reuse the browser's Network cache.
// Requests made from within an extension do not share the page's Network cache,
// but messages can be sent from the UI thread to the content script
// which can make a request from the page's context (with caching).
//
// Some overhead may be incurred sharing (serializing) the loaded data between contexts,
// but less than fetching the file to begin with,
// and in some cases we can avoid serializing the source code at all
// (e.g. when we are in an environment that supports our custom metadata format).
//
// The overall flow of this file is such:
// 1. Find the Set of source files defining the hooks and load them all.
// Then for each source file, do the following:
//
// a. Search loaded source file to see if a source map is available.
// If so, load that file and pass it to a Worker for parsing.
// The source map is used to retrieve the original source,
// which is then also parsed in the Worker to infer hook names.
// This is less ideal because parsing a full source map is slower,
// since we need to evaluate the mappings in order to map the runtime code to the original source,
// but at least the eventual source that we parse to an AST is small/fast.
//
// b. If no source map, pass the full source to a Worker for parsing.
// Use the source to infer hook names.
// This is the least optimal route as parsing the full source is very CPU intensive.
//
// In the future, we may add an additional optimization the above sequence.
// This check would come before the source map check:
//
// a. Search loaded source file to see if a custom React metadata file is available.
// If so, load that file and pass it to a Worker for parsing and extracting.
// This is the fastest option since our custom metadata file is much smaller than a full source map,
// and there is no need to convert runtime code to the original source.
import {__DEBUG__} from 'react-devtools-shared/src/constants';
import {getHookSourceLocationKey} from 'react-devtools-shared/src/hookSourceLocation';
import {sourceMapIncludesSource} from '../SourceMapUtils';
import {
withAsyncPerfMeasurements,
withCallbackPerfMeasurements,
withSyncPerfMeasurements,
} from 'react-devtools-shared/src/PerformanceLoggingUtils';
import type {
HooksNode,
HookSource,
HooksTree,
// ... (448 more lines)
Domain
Subdomains
Functions
Dependencies
- FetchFileWithCachingContext
- PerformanceLoggingUtils
- ReactDebugHooks
- SourceMapTypes.js
- SourceMapUtils.js
- constants
- hookSourceLocation
- sourceMapIncludesSource
Imported By
Source
Frequently Asked Questions
What does loadSourceAndMetadata.js do?
loadSourceAndMetadata.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 loadSourceAndMetadata.js?
loadSourceAndMetadata.js defines 6 function(s): decodeBase64String, extractAndLoadSourceMapJSON, fetchFile, flattenHooksList, hasNamedHooks, loadSourceAndMetadata.
What does loadSourceAndMetadata.js depend on?
loadSourceAndMetadata.js imports 8 module(s): FetchFileWithCachingContext, PerformanceLoggingUtils, ReactDebugHooks, SourceMapTypes.js, SourceMapUtils.js, constants, hookSourceLocation, sourceMapIncludesSource.
What files import loadSourceAndMetadata.js?
loadSourceAndMetadata.js is imported by 2 file(s): index.js, parseSourceAndMetadata.js.
Where is loadSourceAndMetadata.js in the architecture?
loadSourceAndMetadata.js is located at packages/react-devtools-shared/src/hooks/parseHookNames/loadSourceAndMetadata.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-shared/src/hooks/parseHookNames).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free