Skip to content
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

DataTable: Data are not displayed when "Column" has no "field" attributes #4248

Closed
ghostd opened this issue Apr 15, 2023 · 12 comments · Fixed by #4280
Closed

DataTable: Data are not displayed when "Column" has no "field" attributes #4248

ghostd opened this issue Apr 15, 2023 · 12 comments · Fixed by #4280
Assignees
Labels
React 18 Issue or pull request is *only* related to React 18 Type: Bug Issue contains a defect related to a specific component.
Milestone

Comments

@ghostd
Copy link

ghostd commented Apr 15, 2023

Describe the bug

I use DataTable with the callback "body" (without the "field" attribute); no data are displayed in this case (that workend with Prime 8.7.3).

Here is a test to reproduce the case (in addition to the CodeSandbox):

import '@testing-library/jest-dom';
import { render } from "@testing-library/react";
import * as React from "react";
import { Column } from '../column/Column';
import { DataTable } from './DataTable';

describe('DataTable', () => {
    test('should display data with Column without field', () => {
        // Arrange
        const { container } = render(<DataTable dataKey={"key"} value={[{ key: 0 }, { key: 2 }]}>
            <Column
                header="Column 1"
                body={(row) => <div>This is column 1 for item {row.key}</div>}
            />
            <Column
                header="Column 2"
                body={(row) => <div>This is column 2 for item {row.key}</div>}
            />
        </DataTable>
        );

        // Assert
        expect(container).toHaveTextContent('This is column 1 for item 0');
        expect(container).toMatchSnapshot();
    });
});

Reproducer

https://codesandbox.io/s/primereact-test-forked-btleh6

PrimeReact version

9.2.3

React version

18.x

Language

TypeScript

Build / Runtime

Create React App (CRA)

Browser(s)

No response

Steps to reproduce the behavior

No response

Expected behavior

No response

@ghostd ghostd added the Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible label Apr 15, 2023
@melloware melloware added Type: Bug Issue contains a defect related to a specific component. and removed Status: Needs Triage Issue will be reviewed by Core Team and a relevant label will be added as soon as possible labels Apr 16, 2023
@melloware
Copy link
Member

Definitely a bug..great reproducer.

@melloware
Copy link
Member

Interesting trying to reproduce it in the Showcase which is NextJS it seems to be working.

image

Still investigating.

@melloware
Copy link
Member

Weird it works in Vite on StackBlitz also: https://stackblitz.com/edit/react-rhjloz?file=src%2FApp.js

@melloware melloware added Status: Discussion Issue or pull request needs to be discussed by Core Team and removed Type: Bug Issue contains a defect related to a specific component. labels Apr 20, 2023
@ghostd
Copy link
Author

ghostd commented Apr 24, 2023

@melloware i found the difference (but not the actual explanation) between the CodeSandbox sample and the StackBlitz sample, the React strict mode. I you add the <React.StrictMode/> into the code sandbox, the code works; if you remove the <React.StrictMode/> from StackBlitz, the code fails.

@melloware melloware added React 18 Issue or pull request is *only* related to React 18 Type: Bug Issue contains a defect related to a specific component. and removed Status: Discussion Issue or pull request needs to be discussed by Core Team labels Apr 24, 2023
@melloware
Copy link
Member

OK good we have seen other Strict Mode issues in the past as well. I marked it as "React 18" label and that will help us look for the issue.

@ghostd
Copy link
Author

ghostd commented Apr 24, 2023

The Strict mode seems to involve a second rendering phase, which makes the code work. It could be a bug with badly initialised state?

@melloware
Copy link
Member

yep that is what it has been before something not initializing defensively. You can see some other StrictMode issues we have fixed before in this list: https://github.com/primefaces/primereact/issues?q=is%3Aissue+label%3A%22React+18%22+is%3Aclosed

@ghostd
Copy link
Author

ghostd commented Apr 24, 2023

I think it's related to the d_filtersState state... still investigating.

melloware added a commit to melloware/primereact that referenced this issue Apr 24, 2023
@melloware
Copy link
Member

OK can you try my fix.

@melloware
Copy link
Member

Sorry just posted: #4280

Can you try that and let me know. Locally it seems to be working in Strict Mode and non Strict Mode

@melloware
Copy link
Member

the useMount effect is usually the culprit in React Strict Mode 18 issues.

@ghostd
Copy link
Author

ghostd commented Apr 25, 2023

It works for me, thanks.

mertsincan added a commit that referenced this issue Apr 25, 2023
@mertsincan mertsincan added this to the 9.3.1 milestone Apr 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
React 18 Issue or pull request is *only* related to React 18 Type: Bug Issue contains a defect related to a specific component.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants