SIGN IN SIGN UP
facebook / react UNCLAIMED

The library for web and native user interfaces.

244237 0 30 JavaScript
2019-08-13 21:59:07 -07:00
'use strict';
chore[react-devtools/extensions]: make source maps url relative (#29886) This adds few changes: 1. We are going to ship source maps only for 2 artifacts: `installHook.js` and `react_devtools_backend_compact.js`, because it is only these modules that can patch console and be visible to the user via stack traces in console. We need to ship source maps to be able to use `ignoreList` feature in source maps, so we can actually hide these from stack traces. | Before | After | |--------|--------| | ![Screenshot 2024-06-13 at 17 44 25](https://github.com/facebook/react/assets/28902667/464e097b-a95e-47eb-967c-0579daad316b) | ![Screenshot 2024-06-13 at 17 39 53](https://github.com/facebook/react/assets/28902667/e4afe642-d65b-4296-a2cf-26c0b925ebf2) | 2. The `"sources"` field in source map will have relative urls listed, instead of absolute with `webpack://` protocol. This will move the sources to the `React Developer Tools` frame in `Sources` panel, instead of `webpack://`. | Before | After | |--------|--------| | ![Screenshot 2024-06-13 at 17 48 24](https://github.com/facebook/react/assets/28902667/a18edad2-5b4e-4ad7-8a7a-8b389c2edf92) | ![Screenshot 2024-06-13 at 17 49 41](https://github.com/facebook/react/assets/28902667/5db491f7-5d1d-4155-9910-16ac4384d34e) | > [!NOTE] > I still have 1 unresolved issue with shipping source maps in extension build, and it is related to Firefox, which can't find them in the extension bundle and returns 404, even though urls are relative and I can actually open them via unique address like `moz-extension://<extension-id>/build/intallHook.js.map` ¯\\\_(ツ)\_/¯
2024-06-17 11:58:19 +01:00
const {resolve, isAbsolute, relative} = require('path');
const Webpack = require('webpack');
const TerserPlugin = require('terser-webpack-plugin');
chore[react-devtools]: unify console patching and default to ansi escape symbols (#29869) Stacked on https://github.com/facebook/react/pull/29856. ## Summary By default, React DevTools will apply dimming with ANSI escape symbols, so it works for both terminals and browser consoles. For Firefox, which doesn't support ANSI escape symbols console stylings, we fallback to css properties, like we used to do before. ## How did you test this change? | Environment | Dark mode | Light mode | |--------|--------|--------| | Terminal | ![Screenshot 2024-06-12 at 19 39 46](https://github.com/facebook/react/assets/28902667/2d470eee-ec5f-4362-be7d-8d80c6c72d09) | ![Screenshot 2024-06-12 at 19 39 09](https://github.com/facebook/react/assets/28902667/616f2c58-a251-406b-aee6-841e07d652ba) | | Fusebox&nbsp;console | ![Screenshot 2024-06-12 at 21 03 14](https://github.com/facebook/react/assets/28902667/6050f730-8e82-4aa1-acbc-7179aac3a8aa) | ![Screenshot 2024-06-12 at 21 02 48](https://github.com/facebook/react/assets/28902667/6708b938-8a90-476f-a057-427963d58caa) | | Firefox&nbsp;console | ![Screenshot 2024-06-12 at 21 40 29](https://github.com/facebook/react/assets/28902667/4721084f-bbfa-438c-b61b-395da8ded590) | ![Screenshot 2024-06-12 at 21 40 42](https://github.com/facebook/react/assets/28902667/72bbf001-2d3d-49e7-91c9-20a4f0914d4d) | | Chrome&nbsp;console | ![Screenshot 2024-06-12 at 21 43 09](https://github.com/facebook/react/assets/28902667/93c47881-a0dd-44f8-8dc2-8710149774e5) | ![Screenshot 2024-06-12 at 21 43 00](https://github.com/facebook/react/assets/28902667/07ea4ff5-4322-4db9-9c12-4321d9577c9d) |
2024-06-17 16:31:36 +01:00
const {GITHUB_URL, getVersionString} = require('./utils');
const {resolveFeatureFlags} = require('react-devtools-shared/buildUtils');
const SourceMapIgnoreListPlugin = require('react-devtools-shared/SourceMapIgnoreListPlugin');
const {StatsWriterPlugin} = require('webpack-stats-plugin');
2019-01-22 11:04:37 -08:00
const NODE_ENV = process.env.NODE_ENV;
if (!NODE_ENV) {
console.error('NODE_ENV not set');
process.exit(1);
}
const builtModulesDir = resolve(
__dirname,
'..',
'..',
'build',
'oss-experimental',
);
2019-04-18 14:45:24 -07:00
const __DEV__ = NODE_ENV === 'development';
2019-01-22 11:04:37 -08:00
const DEVTOOLS_VERSION = getVersionString(process.env.DEVTOOLS_VERSION);
const EDITOR_URL = process.env.EDITOR_URL || null;
const LOGGING_URL = process.env.LOGGING_URL || null;
const IS_CHROME = process.env.IS_CHROME === 'true';
const IS_FIREFOX = process.env.IS_FIREFOX === 'true';
const IS_EDGE = process.env.IS_EDGE === 'true';
const IS_INTERNAL_VERSION = process.env.FEATURE_FLAG_TARGET === 'extension-fb';
const featureFlagTarget = process.env.FEATURE_FLAG_TARGET || 'extension-oss';
let statsFileName = `webpack-stats.${featureFlagTarget}.${__DEV__ ? 'development' : 'production'}`;
if (IS_CHROME) {
statsFileName += `.chrome`;
}
if (IS_FIREFOX) {
statsFileName += `.firefox`;
}
if (IS_EDGE) {
statsFileName += `.edge`;
}
statsFileName += '.json';
const babelOptions = {
configFile: resolve(
__dirname,
'..',
'react-devtools-shared',
'babel.config.js',
),
};
2019-01-22 11:04:37 -08:00
module.exports = {
mode: __DEV__ ? 'development' : 'production',
devtool: false,
2019-01-22 11:04:37 -08:00
entry: {
backend: './src/backend.js',
background: './src/background/index.js',
backendManager: './src/contentScripts/backendManager.js',
fallbackEvalContext: './src/contentScripts/fallbackEvalContext.js',
fileFetcher: './src/contentScripts/fileFetcher.js',
main: './src/main/index.js',
2019-03-17 13:52:37 -07:00
panel: './src/panel.js',
proxy: './src/contentScripts/proxy.js',
prepareInjection: './src/contentScripts/prepareInjection.js',
installHook: './src/contentScripts/installHook.js',
hookSettingsInjector: './src/contentScripts/hookSettingsInjector.js',
2019-01-22 11:04:37 -08:00
},
output: {
path: __dirname + '/build',
publicPath: '/build/',
filename: chunkData => {
switch (chunkData.chunk.name) {
case 'backend':
return 'react_devtools_backend_compact.js';
default:
return '[name].js';
}
},
Add named hooks support to react-devtools-inline (#22263) This commit builds on PR #22260 and makes the following changes: * Adds a DevTools feature flag for named hooks support. (This allows us to disable it entirely for a build via feature flag.) * Adds a new Suspense cache for dynamically imported modules. (This allows a component to suspend while importing an external code chunk– like the hook names parsing code). * DevTools supports a hookNamesModuleLoaderFunction param to import the hook names module. I wish this could be handles as part of the react-devtools-shared package, but I'm not sure how to configure Webpack (4) to serve the chunk from react-devtools-inline. This seemed like a reasonable workaround. The PR also contains an additional unrelated change: * Removes pre-fetch optimization (added in DevTools: Improve named hooks network caching #22198). This optimization was mostly only important for cases where sources needed to be re-downloaded, something which we can now avoid in most cases¹ thanks to using cached responses already loaded by the page. (I tested this locally on Facebook and this change has no negative performance impact. There is still some overhead from serializing the JS through the Bridge but that's constant between the two approaches.) ¹ The case where we don't benefit from cached responses is when DevTools are opened after the page has already loaded certain scripts. This seems uncommon enough that I don't think it justified the added complexity of prefetching.
2021-09-09 15:25:26 -04:00
chunkFilename: '[name].chunk.js',
2019-01-22 11:04:37 -08:00
},
node: {
global: false,
},
resolve: {
alias: {
react: resolve(builtModulesDir, 'react'),
2019-08-14 10:33:33 -07:00
'react-debug-tools': resolve(builtModulesDir, 'react-debug-tools'),
'react-devtools-feature-flags': resolveFeatureFlags(featureFlagTarget),
Move createRoot/hydrateRoot to react-dom/client (#23385) * Move createRoot/hydrateRoot to /client We want these APIs ideally to be imported separately from things you might use in arbitrary components (like flushSync). Those other methods are "isomorphic" to how the ReactDOM tree is rendered. Similar to hooks. E.g. importing flushSync into a component that only uses it on the client should ideally not also pull in the entry client implementation on the server. This also creates a nicer parity with /server where the roots are in a separate entry point. Unfortunately, I can't quite do this yet because we have some legacy APIs that we plan on removing (like findDOMNode) and we also haven't implemented flushSync using a flag like startTransition does yet. Another problem is that we currently encourage these APIs to be aliased by /profiling (or unstable_testing). In the future you don't have to alias them because you can just change your roots to just import those APIs and they'll still work with the isomorphic forms. Although we might also just use export conditions for them. For that all to work, I went with a different strategy for now where the real API is in / but it comes with a warning if you use it. If you instead import /client it disables the warning in a wrapper. That means that if you alias / then import /client that will inturn import the alias and it'll just work. In a future breaking changes (likely when we switch to ESM) we can just remove createRoot/hydrateRoot from / and move away from the aliasing strategy. * Update tests to import from react-dom/client * Fix fixtures * Update warnings * Add test for the warning * Update devtools * Change order of react-dom, react-dom/client alias I think the order matters here. The first one takes precedence. * Require react-dom through client so it can be aliased Co-authored-by: Andrew Clark <git@andrewclark.io>
2022-03-01 00:13:28 -05:00
'react-dom/client': resolve(builtModulesDir, 'react-dom/client'),
'react-dom': resolve(builtModulesDir, 'react-dom'),
2019-08-14 10:33:33 -07:00
'react-is': resolve(builtModulesDir, 'react-is'),
scheduler: resolve(builtModulesDir, 'scheduler'),
},
},
optimization: {
minimize: !__DEV__,
minimizer: [
new TerserPlugin({
terserOptions: {
compress: {
unused: true,
dead_code: true,
},
mangle: {
keep_fnames: true,
},
format: {
comments: false,
},
},
extractComments: false,
}),
],
},
plugins: [
new Webpack.ProvidePlugin({
process: 'process/browser',
}),
new Webpack.DefinePlugin({
__DEV__,
__EXPERIMENTAL__: true,
__EXTENSION__: true,
__PROFILE__: false,
__TEST__: NODE_ENV === 'test',
__IS_CHROME__: IS_CHROME,
__IS_FIREFOX__: IS_FIREFOX,
__IS_EDGE__: IS_EDGE,
__IS_NATIVE__: false,
__IS_INTERNAL_VERSION__: IS_INTERNAL_VERSION,
'process.env.DEVTOOLS_PACKAGE': `"react-devtools-extensions"`,
'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
'process.env.EDITOR_URL': EDITOR_URL != null ? `"${EDITOR_URL}"` : null,
'process.env.GITHUB_URL': `"${GITHUB_URL}"`,
'process.env.LOGGING_URL': `"${LOGGING_URL}"`,
'process.env.NODE_ENV': `"${NODE_ENV}"`,
}),
new Webpack.SourceMapDevToolPlugin({
filename: '[file].map',
include: ['installHook.js', 'react_devtools_backend_compact.js'],
noSources: !__DEV__,
chore[react-devtools/extensions]: make source maps url relative (#29886) This adds few changes: 1. We are going to ship source maps only for 2 artifacts: `installHook.js` and `react_devtools_backend_compact.js`, because it is only these modules that can patch console and be visible to the user via stack traces in console. We need to ship source maps to be able to use `ignoreList` feature in source maps, so we can actually hide these from stack traces. | Before | After | |--------|--------| | ![Screenshot 2024-06-13 at 17 44 25](https://github.com/facebook/react/assets/28902667/464e097b-a95e-47eb-967c-0579daad316b) | ![Screenshot 2024-06-13 at 17 39 53](https://github.com/facebook/react/assets/28902667/e4afe642-d65b-4296-a2cf-26c0b925ebf2) | 2. The `"sources"` field in source map will have relative urls listed, instead of absolute with `webpack://` protocol. This will move the sources to the `React Developer Tools` frame in `Sources` panel, instead of `webpack://`. | Before | After | |--------|--------| | ![Screenshot 2024-06-13 at 17 48 24](https://github.com/facebook/react/assets/28902667/a18edad2-5b4e-4ad7-8a7a-8b389c2edf92) | ![Screenshot 2024-06-13 at 17 49 41](https://github.com/facebook/react/assets/28902667/5db491f7-5d1d-4155-9910-16ac4384d34e) | > [!NOTE] > I still have 1 unresolved issue with shipping source maps in extension build, and it is related to Firefox, which can't find them in the extension bundle and returns 404, even though urls are relative and I can actually open them via unique address like `moz-extension://<extension-id>/build/intallHook.js.map` ¯\\\_(ツ)\_/¯
2024-06-17 11:58:19 +01:00
// https://github.com/webpack/webpack/issues/3603#issuecomment-1743147144
moduleFilenameTemplate(info) {
const {absoluteResourcePath, namespace, resourcePath} = info;
if (isAbsolute(absoluteResourcePath)) {
return relative(__dirname + '/build', absoluteResourcePath);
}
// Mimic Webpack's default behavior:
return `webpack://${namespace}/${resourcePath}`;
},
}),
new SourceMapIgnoreListPlugin({
shouldIgnoreSource: (assetName, _source) => {
if (__DEV__) {
// Don't ignore list anything in DEV build for debugging purposes
return false;
}
const contentScriptNamesToIgnoreList = [
'react_devtools_backend_compact',
// This is where we override console
'installHook',
];
return contentScriptNamesToIgnoreList.some(ignoreListName =>
assetName.startsWith(ignoreListName),
);
},
}),
{
apply(compiler) {
if (__DEV__) {
return;
}
const {RawSource} = compiler.webpack.sources;
compiler.hooks.compilation.tap(
'CustomContentForHookScriptPlugin',
compilation => {
compilation.hooks.processAssets.tap(
{
name: 'CustomContentForHookScriptPlugin',
stage: Webpack.Compilation.PROCESS_ASSETS_STAGE_DEV_TOOLING,
additionalAssets: true,
},
assets => {
// eslint-disable-next-line no-for-of-loops/no-for-of-loops
for (const [name, asset] of Object.entries(assets)) {
if (name !== 'installHook.js.map') {
continue;
}
const mapContent = asset.source().toString();
if (!mapContent) {
continue;
}
const map = JSON.parse(mapContent);
map.sourcesContent = map.sources.map(sourceName => {
if (!sourceName.endsWith('/hook.js')) {
return null;
}
return (
'/*\n' +
' * This script is from React DevTools.\n' +
" * You're likely here because you thought it sent an error or warning to the console.\n" +
' * React DevTools patches the console to support features like appending component stacks, \n' +
' * so this file appears as a source. However, the console call actually came from another script.\n' +
" * To remove this script from stack traces, open your browser's DevTools (to enable source mapping) before these console calls happen.\n" +
' */'
);
});
compilation.updateAsset(
name,
new RawSource(JSON.stringify(map)),
);
}
},
);
},
);
},
},
new StatsWriterPlugin({
stats: 'verbose',
filename: statsFileName,
}),
],
2019-01-22 11:04:37 -08:00
module: {
defaultRules: [
{
type: 'javascript/auto',
resolve: {},
},
{
test: /\.json$/i,
type: 'json',
},
],
2019-01-22 11:04:37 -08:00
rules: [
{
test: /\.worker\.js$/,
use: [
{
loader: 'workerize-loader',
options: {
inline: false,
name: '[name]',
},
},
{
loader: 'babel-loader',
options: babelOptions,
},
],
},
2019-01-22 11:04:37 -08:00
{
test: /\.js$/,
loader: 'babel-loader',
options: babelOptions,
2019-01-22 11:04:37 -08:00
},
{
test: /\.css$/,
use: [
{
loader: 'style-loader',
},
{
loader: 'css-loader',
options: {
sourceMap: __DEV__,
2019-01-22 11:04:37 -08:00
modules: true,
localIdentName: '[local]___[hash:base64:5]',
},
},
],
},
],
},
};