patternfly / patternfly-react

A set of React components for the PatternFly project.
https://react-staging.patternfly.org/
MIT License
778 stars 353 forks source link

Bug - Table - treeview table rendering crashes when an empty string is passed to a `Td` child #10185

Open dvail opened 6 months ago

dvail commented 6 months ago

Describe the problem

As titled, when using the tree view table variant if an empty string is passed as a child of a cell, React will throw an error during rendering:

Objects are not valid as a React child (found: object with keys {title}). If you meant to render a collection of children, use an array instead.

With some local debugging I suspect the issue stems from this line, which unintentionally returns an object when object.title is falsy.

How do you reproduce the problem?

It looks like CodeSandbox no longer allows public links on a free account, but the following minimal snippet will reproduce the issue:

import ReactDOM from 'react-dom';
import '@patternfly/react-core/dist/styles/base.css';

import * as React from 'react';
import { Table, Thead, Tbody, Tr, Th, Td, TreeRowWrapper } from '@patternfly/react-table';

function YourIssue() {
    return (
        <Table isTreeTable>
            <Thead>
                <Tr>
                    <Th>Test</Th>
                </Tr>
            </Thead>
            <Tbody>
                <TreeRowWrapper row={{ props: {} }}>
                    <Td treeRow={{ onCollapse: () => {}, props: {} }}>{''}</Td>
                </TreeRowWrapper>
            </Tbody>
        </Table>
    );
}

ReactDOM.render(<YourIssue />, document.getElementById('root'));

This impacts at least as far back as @patternfly/react-table : 4.112.39 as well as latest.

Expected behavior The table renders an empty string without a runtime error.

Is this issue blocking you? No - the workaround is to guard for empty strings when rendering a tree view Table and provide an alternative value.

Screenshots image

github-actions[bot] commented 4 months ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

github-actions[bot] commented 2 months ago

This issue has been automatically marked as stale because it has not had recent activity.

github-actions[bot] commented 1 week ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.