Skip to content

Convert describeComponentFrame to createRoot #28001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions packages/shared/__tests__/describeComponentFrame-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@
'use strict';

let React;
let ReactDOM;
let ReactDOMClient;
let act;

describe('Component stack trace displaying', () => {
beforeEach(() => {
React = require('react');
ReactDOM = require('react-dom');
ReactDOMClient = require('react-dom');
act = require('internal-test-utils').act;
});

// @gate !enableComponentStackLocations || !__DEV__
it('should provide filenames in stack traces', () => {
it('should provide filenames in stack traces', async () => {
class Component extends React.Component {
render() {
return [<span>a</span>, <span>b</span>];
Expand Down Expand Up @@ -88,15 +90,21 @@ describe('Component stack trace displaying', () => {
'C:\\funny long (path)/index.js': 'funny long (path)/index.js',
'C:\\funny long (path)/index.jsx': 'funny long (path)/index.jsx',
};
Object.keys(fileNames).forEach((fileName, i) => {

const root = ReactDOMClient.createRoot(container);

let i = 0;
for (const fileName in fileNames) {
Copy link
Member

@rickhanlonii rickhanlonii Jan 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for (let i = 0; i < fileNames.length; i++) {

or

for (let [i, fileName] of fileNames.entries()) {

?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fileNames is an object so a basic for loop would also be awkward. We already had precedent below to iterate over fileNames with for-in and manual increments.

for-of would trigger lint violations and while it's likely a false-positive for tests, I just stuck with what's already there. But I agree that for-in with increments is pretty unorthodox.

Component.displayName = 'Component ' + i;
ReactDOM.render(
<Component __source={{fileName, lineNumber: i}} />,
container,
);
});

await act(() => {
root.render(<Component __source={{fileName, lineNumber: i}} />);
});

i++;
}
if (__DEV__) {
let i = 0;
i = 0;
expect(console.error).toHaveBeenCalledTimes(
Object.keys(fileNames).length,
);
Expand Down