Closed lucaswalter closed 1 year ago
To clarify further, this seems to only happen when I utilize "Cell Formatting" on the table like in this snippet:
export const columns: ColumnDef<Payment>[] = [
{
accessorKey: 'status',
header: 'Status',
},
{
accessorKey: 'email',
header: 'Email',
},
{
accessorKey: 'amount',
// header: 'Amount', // This works for me
header: () => <div className="text-right">Amount</div>, // This does not work for me
},
];
Hi, I tried to reproduce this issue. According to my findings the react 18 version is creating the issue. Try to use react 17 version and it will fix most of the hydration errors.
In React 18 here are some of the breaking changes that might be responsible for this.
React.render
will warn you that you should replace it with React.createRoot
ReactDOM.hydrate
will tell you the same about React.hydrateRoot
Thanks @Rohan-07 for the additional context and for sharing your findings. It will be difficult for me to downgrade to react 17 because of other peer dependencies I have in my project.
From what you found, was the React.render
and ReactDOM.hydrate
usage actually in the @tanstack/react-table
dependency? Or was it used somewhere else?
I personally think it may be best to go forward raising an issue in the appropriate spot so it can be fixed on the latest dependency versions. Would you mind sharing a bit more context around that? I'd be happy to take forward with reporting the issue.
Workaround documented here: https://discord.com/channels/830184174198718474/1130952479555735612
@lucaswalter can you share your findings? This link is broken and I am in the same boat as you.
@lucaswalter can you share your findings? This link is broken and I am in the same boat as you.
Heres the link it referenced. Discord links are bad because you cant really index the discord stuff. So I'm going to copy/paste the reference here for future reference:
here another solution
on the unmodified example from lucaswalter repo just change this
<DataTable client:load columns={columns} data={data} />
to this, (removing the client directive)
<DataTable columns={columns} data={data} />
this shows a sort of mismatch between react usage as a component rendered by Astro on server side and the workaround usage as client component when wrapped in another jsx.
When removing the client:load directive, there's obviously no react on client anymore and it's all rendered to html by astro on serevr side```
Any idea how to fix this hydration error ?
@tannerlinsley This bug made the react table useless as it can't be used in Astro.js anyway
This seems more like an astro/react bug than a TanStack Table bug. I don't know how we would package this differently that would make a difference.
PS: The Astro author says vice versa like this is a library bug and I can confirm it is a react-table bug because In the past I did debug the issue and the react table was adding an unnecessary div inside the tag which creates the problem.
More detail here: https://github.com/withastro/astro/issues/10860
Do you think that the problem is that your column definitions are not defined inside of a react component? Anything with jsx like a custom cell render should probably only be defined inside of react, and not in an Astro file.
Actually, it could be a related bug too if I create the react table as separate component then import into astro page then it works fine without hydration error.
page.astro
---
import Layout from '../layouts/Layout.astro'
import { DataTable } from '@/components/datatable/datatable'
import { createColumnHelper } from '@tanstack/react-table'
const columnHelper = createColumnHelper()
const columns = [
columnHelper.accessor('name', {
cell: (info) => info.getValue(),
}),
]
const defaultData = [
{
name: 'tanner',
lastName: 'linsley',
age: 24,
visits: 100,
status: 'In Relationship',
progress: 50,
},
]
---
<Layout title='List of Countries in the World'>
<DataTable data={defaultData} columns={columns} client:load />
</Layout>
chunk-BVI7NZOO.js?v=4b8af205:521 Warning: Did not expect server HTML to contain the text node "tanner" in <td>.
at td
at _c13 (http://localhost:4321/src/components/ui/table.tsx:142:13)
at tr
at _c9 (http://localhost:4321/src/components/ui/table.tsx:96:12)
at tbody
at _c5 (http://localhost:4321/src/components/ui/table.tsx:53:12)
at table
at div
at _c (http://localhost:4321/src/components/ui/table.tsx:20:11)
at div
Separate React Component TestTable.tsx
import { createColumnHelper } from '@tanstack/react-table'
import { DataTable } from '@/components/datatable/datatable'
const columnHelper = createColumnHelper()
const columns = [
columnHelper.accessor('name', {
cell: (info) => info.getValue(),
}),
]
const defaultData = [
{
name: 'tanner',
lastName: 'linsley',
age: 24,
visits: 100,
status: 'In Relationship',
progress: 50,
},
]
export const Demo1 = () => {
return <DataTable data={defaultData} columns={columns} />
}
page.astro
---
import Layout from '../layouts/Layout.astro'
import { Demo1 } from '@/components/rt/Demo1'
---
<Layout title='List of Countries in the World'>
<Demo1 />
</Layout>
Describe the bug
Hello, I'm having a bit of trouble tracing down the root of this so forgive me if this is not the correct spot to note this but I wanted to raise an issue to see if anyone else has encountered this or has a path forward.
I am using shadcn inside an Astro project and am attempting to display data in a
DataTable
component as documented on the shadcn documentation site. When I attempt to run the website locally, I get this hydration error when trying to apply custom formatting or JSX to theheader
orcell
items on myColumnDef
. An error occurred during hydration. The server HTML was replaced with client content in 'astro-island'I've been able to reproduce this exact same issue on a fresh repro project after following these exact steps:
Here is the repro link which uses exact same component as in the docs: https://github.com/lucaswalter/astro-shadcn-tanstack-repro/blob/main/src/pages/index.astro
In short, I am attempting to render and hydrate the
DataTable
like in the snippet below. Is it currently possible to use the DataTable component in an Astro project?Full Strack Trace
Your minimal, reproducible example
https://stackblitz.com/github/lucaswalter/astro-shadcn-tanstack-repro
Steps to reproduce
See the repro project here: https://github.com/lucaswalter/astro-shadcn-tanstack-repro/blob/main/src/pages/index.astro#L41 or StackBlitz
npm run dev
Expected behavior
As a user, I expect to be able to provide custom
cell
andheader
JSX which will render and hydrate on my website.How often does this bug happen?
Every time
Screenshots or Videos
Platform
react-table version
^8.9.3
TypeScript version
No response
Additional context
No response
Terms & Code of Conduct