nextui icon indicating copy to clipboard operation
nextui copied to clipboard

[BUG] - Table with multiple select leads to matching error

Open peterhijma opened this issue 2 years ago • 21 comments

NextUI Version

2.1.13

Describe the bug

Using Remix (SSR) I have a table with "multiple select" enabled. It gives me this error:

Warning: Prop `data-key` did not match. Server: "row-header-column-fqu8o02955" Client: "row-header-column-al3odv09eyg"

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

  1. Enable multiple select for the table
  2. Error in the console

Expected behavior

There is no mismatch between server/client.

Screenshots or Videos

No response

Operating System Version

macOS

Browser

Chrome

peterhijma avatar Oct 02 '23 07:10 peterhijma

I'm having the same error using nextjs and "use client" https://stackblitz.com/edit/github-mfb9ja

image

thegostisdead avatar Oct 30 '23 11:10 thegostisdead

same error here, and single select seems not to be working.

fsolarv22 avatar Oct 30 '23 16:10 fsolarv22

I have same error.

yukimasaki avatar Jan 11 '24 05:01 yukimasaki

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.

seb350 avatar Jan 12 '24 20:01 seb350

also having this issue

alexander-densley avatar Feb 07 '24 17:02 alexander-densley

I'm also having the same problem, it only happens when multiple selection is activated, for single selection this doesn't happen.

Lucasmm016 avatar Feb 08 '24 16:02 Lucasmm016

I also have this issue

elanclarkson avatar Feb 19 '24 04:02 elanclarkson

@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.

cheestudio avatar Feb 26 '24 03:02 cheestudio

What do you mean continuously? I've posted it once lol or are your counting skills just like your programming ones?

seb350 avatar Feb 26 '24 06:02 seb350

You posted it here, as well, and it wasn't helpful there, either.

https://github.com/nextui-org/nextui/issues/779

cheestudio avatar Feb 26 '24 14:02 cheestudio

If you understand it, it's helpful.

seb350 avatar Feb 26 '24 14:02 seb350

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"

rsemihkoca avatar Feb 29 '24 17:02 rsemihkoca

This error like Hydration failed

Solution 1: You can using useEffect to run on the client only

https://nextjs.org/docs/messages/react-hydration-error#solution-1-using-useeffect-to-run-on-the-client-only

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>
  )
}

Solution 2: Disable SSR on the parent component

https://nextjs.org/docs/messages/react-hydration-error#solution-2-disabling-ssr-on-specific-components

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.

Cainier avatar May 16 '24 14:05 Cainier

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 avatar Aug 01 '24 12:08 GVALFER