icflorescu / mantine-datatable

The table component for your Mantine data-rich applications, supporting asynchronous data loading, column sorting, custom cell data rendering, context menus, nesting, Gmail-style batch row selection, dark theme, and more.
https://icflorescu.github.io/mantine-datatable/
MIT License
950 stars 68 forks source link

Takes a lot of time for autocomplete in the table + tsserver lagging #504

Closed hitfm00 closed 10 months ago

hitfm00 commented 10 months ago

Reproduce: 1) <DataTable columns={[{ accessor: "title" }]} records={data} />; 2) Then just type some lo <DataTable columns={[{ accessor: "title" }]} records={data} lo />; 3) And wait 4 second when we will see autocomplete

Снимок экрана 2024-01-05 в 03 20 05

In other components for me all good, only with this it takes so long time :)

icflorescu commented 10 months ago

It does take a while indeed, as DataTable is a component with lots of properties and the TS server needs some time to perform its autocomplete magic.

This is the main drawback of having a React component (or any kind of function, for that matter) with so many configuration options that are properly validated and documented with TS. The same happens, for instance, if you're using things like tRPC, which are heavily based on dynamic types...

For instance, have a look at how the sorting-related prop types are defined: https://github.com/icflorescu/mantine-datatable/blob/main/package/types/DataTableSortProps.ts This is to make sure that providing onSortStatusChange callback only makes sense if you also provide a sortStatus property. Another example is this: the column accessor type is described like so:

accessor: keyof T | (string & NonNullable<unknown>);

This way, the editor will be able to suggest properties inferred from the type of records, but won't limit you to that.

It doesn't take 4s, though. On my machine, a not-so-new Ryzen7 4800u laptop with Manjaro Linux, the scenario you are describing takes about one second for the autocomplete to trigger.

I may be subjective, but all-in-all, I'd say it's an acceptable trade-off. I could relax the typings, but then we'd have a lot of uncaught errors, especially nowadays when we're working in such as fast-paced environment and devs tend to skip the docs and jump straight into code :-). Dealing with bugs introduced by improper prop combinations and validations would cost you way more than one or even four seconds.

icflorescu commented 10 months ago

Going to convert this to a discussion.