Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -2169,6 +2169,29 @@ describe('ReactInternalTestUtils console assertions', () => {
+ Bye in div (at **)"
`);
});

// @gate __DEV__
it('fails if last received error containing "undefined" is not included', () => {
const message = expectToThrowFailure(() => {
console.error('Hi');
console.error(
"TypeError: Cannot read properties of undefined (reading 'stack')\n" +
' in Foo (at **)'
);
assertConsoleErrorDev([['Hi', {withoutStack: true}]]);
});
expect(message).toMatchInlineSnapshot(`
"assertConsoleErrorDev(expected)

Unexpected error(s) recorded.

- Expected errors
+ Received errors

Hi
+ TypeError: Cannot read properties of undefined (reading 'stack') in Foo (at **)"
`);
});
// @gate __DEV__
it('fails if only error does not contain a stack', () => {
const message = expectToThrowFailure(() => {
Expand Down
7 changes: 4 additions & 3 deletions packages/internal-test-utils/consoleMock.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ export function createLogAssertion(
let argIndex = 0;
// console.* could have been called with a non-string e.g. `console.error(new Error())`
// eslint-disable-next-line react-internal/safe-string-coercion
String(format).replace(/%s|%c/g, () => argIndex++);
String(format).replace(/%s|%c|%o/g, () => argIndex++);
if (argIndex !== args.length) {
if (format.includes('%c%s')) {
// We intentionally use mismatching formatting when printing badging because we don't know
Expand All @@ -382,8 +382,9 @@ export function createLogAssertion(

// Main logic to check if log is expected, with the component stack.
if (
normalizedMessage === expectedMessage ||
normalizedMessage.includes(expectedMessage)
typeof expectedMessage === 'string' &&
(normalizedMessage === expectedMessage ||
normalizedMessage.includes(expectedMessage))
) {
if (isLikelyAComponentStack(normalizedMessage)) {
if (expectedWithoutStack === true) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import FetchFileWithCachingContext from './FetchFileWithCachingContext';
import {symbolicateSourceWithCache} from 'react-devtools-shared/src/symbolicateSource';
import OpenInEditorButton from './OpenInEditorButton';
import InspectedElementViewSourceButton from './InspectedElementViewSourceButton';
import Skeleton from './Skeleton';
import useEditorURL from '../useEditorURL';

import styles from './InspectedElement.css';
Expand Down Expand Up @@ -203,7 +202,9 @@ export default function InspectedElementWrapper(_: Props): React.Node {
}

return (
<div className={styles.InspectedElement}>
<div
className={styles.InspectedElement}
key={inspectedElementID /* Force reset when selected Element changes */}>
<div className={styles.TitleRow} data-testname="InspectedElement-Title">
{strictModeBadge}

Expand Down Expand Up @@ -232,13 +233,11 @@ export default function InspectedElementWrapper(_: Props): React.Node {
!!editorURL &&
source != null &&
symbolicatedSourcePromise != null && (
<React.Suspense fallback={<Skeleton height={16} width={24} />}>
<OpenInEditorButton
editorURL={editorURL}
source={source}
symbolicatedSourcePromise={symbolicatedSourcePromise}
/>
</React.Suspense>
<OpenInEditorButton
editorURL={editorURL}
source={source}
symbolicatedSourcePromise={symbolicatedSourcePromise}
/>
)}

{canToggleError && (
Expand Down Expand Up @@ -294,9 +293,6 @@ export default function InspectedElementWrapper(_: Props): React.Node {

{inspectedElement !== null && symbolicatedSourcePromise != null && (
<InspectedElementView
key={
inspectedElementID /* Force reset when selected Element changes */
}
element={element}
hookNames={hookNames}
inspectedElement={inspectedElement}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ function InspectedElementSourcePanel({
<div className={styles.SourceHeaderRow}>
<div className={styles.SourceHeader}>source</div>

<React.Suspense fallback={<Skeleton height={16} width={16} />}>
<React.Suspense
fallback={
<Button disabled={true} title="Loading source maps...">
<ButtonIcon type="copy" />
</Button>
}>
<CopySourceButton
source={source}
symbolicatedSourcePromise={symbolicatedSourcePromise}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@
overflow: hidden;
text-overflow: ellipsis;
}

.RenderedBySkeleton {
padding-left: 1.25rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {enableStyleXFeatures} from 'react-devtools-feature-flags';
import InspectedElementSourcePanel from './InspectedElementSourcePanel';
import StackTraceView from './StackTraceView';
import OwnerView from './OwnerView';
import Skeleton from './Skeleton';

import styles from './InspectedElementView.css';

Expand Down Expand Up @@ -170,34 +171,40 @@ export default function InspectedElementView({
className={styles.InspectedElementSection}
data-testname="InspectedElementView-Owners">
<div className={styles.OwnersHeader}>rendered by</div>

{showStack ? <StackTraceView stack={stack} /> : null}
{showOwnersList &&
owners?.map(owner => (
<Fragment key={owner.id}>
<OwnerView
displayName={owner.displayName || 'Anonymous'}
hocDisplayNames={owner.hocDisplayNames}
environmentName={
inspectedElement.env === owner.env ? null : owner.env
}
compiledWithForget={owner.compiledWithForget}
id={owner.id}
isInStore={store.containsElement(owner.id)}
type={owner.type}
/>
{owner.stack != null && owner.stack.length > 0 ? (
<StackTraceView stack={owner.stack} />
) : null}
</Fragment>
))}

{rootType !== null && (
<div className={styles.OwnersMetaField}>{rootType}</div>
)}
{rendererLabel !== null && (
<div className={styles.OwnersMetaField}>{rendererLabel}</div>
)}
<React.Suspense
fallback={
<div className={styles.RenderedBySkeleton}>
<Skeleton height={16} width="40%" />
</div>
}>
{showStack ? <StackTraceView stack={stack} /> : null}
{showOwnersList &&
owners?.map(owner => (
<Fragment key={owner.id}>
<OwnerView
displayName={owner.displayName || 'Anonymous'}
hocDisplayNames={owner.hocDisplayNames}
environmentName={
inspectedElement.env === owner.env ? null : owner.env
}
compiledWithForget={owner.compiledWithForget}
id={owner.id}
isInStore={store.containsElement(owner.id)}
type={owner.type}
/>
{owner.stack != null && owner.stack.length > 0 ? (
<StackTraceView stack={owner.stack} />
) : null}
</Fragment>
))}

{rootType !== null && (
<div className={styles.OwnersMetaField}>{rootType}</div>
)}
{rendererLabel !== null && (
<div className={styles.OwnersMetaField}>{rendererLabel}</div>
)}
</React.Suspense>
</div>
)}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import * as React from 'react';

import ButtonIcon from '../ButtonIcon';
import Button from '../Button';
import Skeleton from './Skeleton';

import type {ReactFunctionLocation} from 'shared/ReactTypes';

Expand All @@ -27,7 +26,12 @@ function InspectedElementViewSourceButton({
symbolicatedSourcePromise,
}: Props): React.Node {
return (
<React.Suspense fallback={<Skeleton height={16} width={24} />}>
<React.Suspense
fallback={
<Button disabled={true} title="Loading source maps...">
<ButtonIcon type="view-source" />
</Button>
}>
<ActualSourceButton
source={source}
symbolicatedSourcePromise={symbolicatedSourcePromise}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@

@keyframes pulse {
0%, 100% {
background-color: var(--color-dim);
background-color: none;
}
50% {
background-color: var(--color-dimmest)
background-color: var(--color-dimmest);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,11 @@ type Props = {
className?: string,
};

function OpenInEditorButton({editorURL, source, className}: Props): React.Node {
function ActualOpenInEditorButton({
editorURL,
source,
className,
}: Props): React.Node {
let disable;
if (source == null) {
disable = true;
Expand Down Expand Up @@ -68,4 +72,22 @@ function OpenInEditorButton({editorURL, source, className}: Props): React.Node {
);
}

function OpenInEditorButton({editorURL, source, className}: Props): React.Node {
return (
<React.Suspense
fallback={
<Button disabled={true} className={className}>
<ButtonIcon type="editor" />
<ButtonLabel>Loading source maps...</ButtonLabel>
</Button>
}>
<ActualOpenInEditorButton
editorURL={editorURL}
source={source}
className={className}
/>
</React.Suspense>
);
}

export default OpenInEditorButton;
21 changes: 21 additions & 0 deletions packages/react-server/src/ReactFlightServer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3354,6 +3354,27 @@ function renderModelDestructive(
task.debugOwner = element._owner;
task.debugStack = element._debugStack;
task.debugTask = element._debugTask;
if (
element._owner === undefined ||
element._debugStack === undefined ||
element._debugTask === undefined
) {
let key = '';
if (element.key !== null) {
key = ' key="' + element.key + '"';
}

console.error(
'Attempted to render <%s%s> without development properties. ' +
'This is not supported. It can happen if:' +
'\n- The element is created with a production version of React but rendered in development.' +
'\n- The element was cloned with a custom function instead of `React.cloneElement`.\n' +
'The props of this element may help locate this element: %o',
element.type,
key,
element.props,
);
}
// TODO: Pop this. Since we currently don't have a point where we can pop the stack
// this debug information will be used for errors inside sibling properties that
// are not elements. Leading to the wrong attribution on the server. We could fix
Expand Down
24 changes: 24 additions & 0 deletions packages/react-server/src/__tests__/ReactFlightServer-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ let ReactNoopFlightServer;
let Scheduler;
let advanceTimersByTime;
let assertLog;
let assertConsoleErrorDev;

describe('ReactFlight', () => {
beforeEach(() => {
Expand Down Expand Up @@ -64,6 +65,7 @@ describe('ReactFlight', () => {
Scheduler = require('scheduler');
const InternalTestUtils = require('internal-test-utils');
assertLog = InternalTestUtils.assertLog;
assertConsoleErrorDev = InternalTestUtils.assertConsoleErrorDev;
});

afterEach(() => {
Expand Down Expand Up @@ -175,4 +177,26 @@ describe('ReactFlight', () => {
stackTwo: '\n in OwnerStackDelayed (at **)' + '\n in App (at **)',
});
});

it('logs an error when prod elements are rendered', async () => {
const element = ReactServer.createElement('span', {
key: 'one',
children: 'Free!',
});
ReactNoopFlightServer.render(
// bad clone
{...element},
);

assertConsoleErrorDev([
[
'Attempted to render <span key="one"> without development properties. This is not supported. It can happen if:' +
'\n- The element is created with a production version of React but rendered in development.' +
'\n- The element was cloned with a custom function instead of `React.cloneElement`.\n' +
"The props of this element may help locate this element: { children: 'Free!', [key]: [Getter] }",
{withoutStack: true},
],
"TypeError: Cannot read properties of undefined (reading 'stack')",
]);
});
});
Loading