Open peterhijma opened 1 year ago
I'm having the same error using nextjs and "use client"
https://stackblitz.com/edit/github-mfb9ja
same error here, and single select seems not to be working.
I have same error.
This happens because there's a mismatch between the server-rendered content and the client-side rendered content, specifically the data-key.
Since NextUI needs "use client" anyway, both your custom Table compoenent and the NextThemesProvider component can be imported using next/dynamic and disable SSR completely.
This:
import TableX from './components/Table';
import { ThemeProvider as NextThemesProvider } from "next-themes";
To this:
const TableX = dynamic( () => import('./components/Table'), { ssr: false } );
const NextThemesProvider = dynamic( () => import('next-themes').then((mod) => mod.ThemeProvider), { ssr: false } );
Then use as imported normally.
also having this issue
I'm also having the same problem, it only happens when multiple selection is activated, for single selection this doesn't happen.
I also have this issue
@seb350 Why are you continuously posting this as a solution? It's a pretty poor band-aid for a much longer standing issue with the library.
What do you mean continuously? I've posted it once lol or are your counting skills just like your programming ones?
You posted it here, as well, and it wasn't helpful there, either.
If you understand it, it's helpful.
Up nextjs 14.1.0. I used same table from documentation with custom style. Multiple selection error still continues
Prop data-key
did not match. Server: "row-header-column-ei75sadomwv" Client: "row-header-column-j5dbc4t8d7"
E.g.
'use client'
// usrs.tsx
export function Users() {
const [ready, setReady] = useState<boolean>(false)
const [selectedKeys, setSelectedKeys] = useState<Set<number>>(new Set())
return ready && (
<Table
aria-label="Users"
selectionMode="multiple"
selectedKeys={selectedKeys}
onSelectionChange={keys => setSelectedKeys(keys as Set<number>)}
>
...
</Table>
)
}
E.g.
// page.ts
import dynamic from 'next/dynamic'
const NoSSR = dynamic(async () => (await import('./users')).Users, { ssr: false })
export default async function PageUserManagement() {
return <>
<NoSSR />
</>
}
Solution 3 on the nextjs official website: Using suppressHydrationWarning has no effect on this problem.
I have the same problem. Ok, it can be fixable using dynamic import, or a, useEffect. BUT the problem is: I load the data using SWR with fallbackData coming with server side to immediatly load the initial data. for that reason i can not use dynamic import or useEffect to load the table, otherwise load data from server side makes no sense. Why nextUI is too confuse ? It seems like everything was done in the middle of total confusion.
A solution (whats is not a solution) is use the useEffect hook, and set the initial state as "single" and when loaded, then pass to "multiple" but it give a flash, what sucks.
@GVALFER Nice one!
Set default prop
isMultipleSelect = true,
`const [selectionMode, setSelectionModle] =
React.useState
useEffect(() => { if (isMultipleSelect) { setSelectionModle("multiple"); } }, [isMultipleSelect]);`
And pass it to Table props
`<Table isHeaderSticky={false} selectionMode={selectionMode} selectedKeys={selectedKeys} onSelectionChange={setSelectedKeys}
...... `
Solved my problem!
This happens because there's a mismatch between the server-rendered content and the client-side rendered content, specifically the data-key.
Since NextUI needs "use client" anyway, both your custom Table compoenent and the NextThemesProvider component can be imported using next/dynamic and disable SSR completely.
This:
import TableX from './components/Table';
import { ThemeProvider as NextThemesProvider } from "next-themes";
To this:
const TableX = dynamic( () => import('./components/Table'), { ssr: false } );
const NextThemesProvider = dynamic( () => import('next-themes').then((mod) => mod.ThemeProvider), { ssr: false } );
Then use as imported normally.
This actually works but the page briefly goes white before switching back to dark mode on refresh (FOUC) :/
@GVALFER Nice one!
Set default prop
isMultipleSelect = true,
`const [selectionMode, setSelectionModle] = React.useState("single");
useEffect(() => { if (isMultipleSelect) { setSelectionModle("multiple"); } }, [isMultipleSelect]);`
And pass it to Table props
<Table isHeaderSticky={false} selectionMode={selectionMode} selectedKeys={selectedKeys} onSelectionChange={setSelectedKeys} > ...... </Table>
Solved my problem!
Great, it's works and I find this solution much maintainable than all the others. Thanks!!
import {
Table,
...
type SelectionMode,
} from '@nextui-org/react'
function useTableSelectionMode(isMultipleSelect: boolean = true) {
const [selectionMode, setSelectionMode] = React.useState('single')
React.useEffect(() => {
if (isMultipleSelect) {
setSelectionMode('multiple')
} else {
setSelectionMode('single')
}
}, [isMultipleSelect])
return selectionMode
}
export default function Test() {
const selectionMode = useTableSelectionMode()
<Table
selectionMode={selectionMode}
......
}
NextUI Version
2.1.13
Describe the bug
Using Remix (SSR) I have a table with "multiple select" enabled. It gives me this error:
I'd like to use SSR and don't feel too happy with wrapping the table with a
ClientOnly
component or something similar.Thanks in advance! Very nice UI library.
Your Example Website or App
No response
Steps to Reproduce the Bug or Issue
Expected behavior
There is no mismatch between server/client.
Screenshots or Videos
No response
Operating System Version
macOS
Browser
Chrome