mirror of
https://github.com/zebrajr/react.git
synced 2025-12-06 12:20:20 +01:00
This adds a "Code Editor" pane for the Chrome extension in the bottom right corner of the "Sources" panel. If you end up getting linked to the "Sources" panel from stack traces in console, performance tab, stacks in React Component tab like the one added in #33954 basically everywhere there's a link to source code. Then going from there to open in a code editor should be more convenient. This adds a button to open the current file. <img width="1387" height="389" alt="Screenshot 2025-07-22 at 10 22 19 PM" src="https://github.com/user-attachments/assets/fe01f84c-83c2-4639-9b64-4af1a90c3f7d" /> This only makes sense in the extensions since in standalone it needs to always open by default in an editor. Unfortunately Firefox doesn't support extending the Sources panel. Chrome is also a bit buggy where it doesn't send a selection update event when you switch tabs in the Sources panel. Only when the actual cursor position changes. This means that the link can be lagging behind sometimes. We also have some general bugs where if React DevTools loses connection it can break the UI which includes this pane too. This has a small inline configuration too so that it's discoverable: <img width="559" height="143" alt="Screenshot 2025-07-22 at 10 22 42 PM" src="https://github.com/user-attachments/assets/1270bda8-ce10-4f9d-9fcb-080c0198366a" /> <img width="527" height="123" alt="Screenshot 2025-07-22 at 10 22 30 PM" src="https://github.com/user-attachments/assets/45848c95-afd8-495f-a7cf-eb2f46e698f2" /> Since we can't add a separate link to open-in-editor or open-in-sources everywhere I plan on adding an option to open in editor by default in a follow up. That option needs to be even more discoverable. I moved the configuration from the Components settings to the General settings since this is now a much more general features for opening links to resources in all types of panes. <img width="673" height="311" alt="Screenshot 2025-07-22 at 10 22 57 PM" src="https://github.com/user-attachments/assets/ea2c0871-942c-4b55-a362-025835d2c2bd" />
48 lines
1.1 KiB
JavaScript
48 lines
1.1 KiB
JavaScript
/**
|
|
* 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
|
|
*/
|
|
|
|
import * as React from 'react';
|
|
|
|
import Button from 'react-devtools-shared/src/devtools/views/Button';
|
|
import ButtonIcon from 'react-devtools-shared/src/devtools/views/ButtonIcon';
|
|
|
|
import type {ReactFunctionLocation} from 'shared/ReactTypes';
|
|
|
|
import {checkConditions} from '../Editor/utils';
|
|
|
|
type Props = {
|
|
editorURL: string,
|
|
source: ReactFunctionLocation,
|
|
symbolicatedSourcePromise: Promise<ReactFunctionLocation | null>,
|
|
};
|
|
|
|
function OpenInEditorButton({
|
|
editorURL,
|
|
source,
|
|
symbolicatedSourcePromise,
|
|
}: Props): React.Node {
|
|
const symbolicatedSource = React.use(symbolicatedSourcePromise);
|
|
|
|
const {url, shouldDisableButton} = checkConditions(
|
|
editorURL,
|
|
symbolicatedSource ? symbolicatedSource : source,
|
|
);
|
|
|
|
return (
|
|
<Button
|
|
disabled={shouldDisableButton}
|
|
onClick={() => window.open(url)}
|
|
title="Open in editor">
|
|
<ButtonIcon type="editor" />
|
|
</Button>
|
|
);
|
|
}
|
|
|
|
export default OpenInEditorButton;
|