Skip to content

Render the actual component for svelte when returned from cell function - #4588

Merged
KevinVandy merged 1 commit into
TanStack:mainfrom
itssumitrai:patch-1
Mar 26, 2023
Merged

KevinVandy merged 1 commit into
TanStack:mainfrom
itssumitrai:patch-1

Conversation

@itssumitrai

Copy link
Copy Markdown
Contributor

Currently the flexRender function checks if the result of cell function is a Svelte component, and if it is, it just returns the actual Component instead of rendering the component with the props. This PR fixes this issue

@KevinVandy

Copy link
Copy Markdown
Member

Would this be a breaking change?

@vd-aloker

Copy link
Copy Markdown

I'd like to see this merged.

It's rather a bugfix than a breaking change.

Here's a usecase of mine:

const columns = [
	display({
		id: 'mail',
		cell: () => EmailColumn,
		header: () => L.colMail()
	})
];
//...
<td>
	<svelte:component this={flexRender(cell.column.columnDef.cell, cell.getContext())} />
</td>

Without the fix, the EmailColumn component won't receive any props. With the fix applied, the EmailColumn component will receive all props from getContext().

The only current workaround is to use the component itself as the value of cell:

display({
	id: 'mail',
	cell: EmailColumn,
	header: 'E-Mail'
}),

But this will a) cause a Typescript error and b) disable the possibility to switch components based on values passed to the cell function.

@bfovez

bfovez commented Mar 21, 2023

Copy link
Copy Markdown

This does seem to me like a major problem. I am currently investigating for a headless Svelte table after been relatively disappointed by Svelte Headless Table (instabilities, ), but that issue is a deal breaker.
I'm surprised that nobody from the team reacted since last december. The fix seems to be pretty straightforward.

@KevinVandy

Copy link
Copy Markdown
Member

Taking @vd-aloker 's word for it

@KevinVandy
KevinVandy merged commit 496be91 into TanStack:main Mar 26, 2023
@KevinVandy

Copy link
Copy Markdown
Member

This PR seems to be causing some issues in #4778 . Do the examples just need to be updated? @itssumitrai @vd-aloker @bfovez

Otherwise this PR may need to be reverted.

@itssumitrai
itssumitrai deleted the patch-1 branch April 3, 2023 17:28
@Eric-Arz

Copy link
Copy Markdown

This completely broke TypeScript in Svelte. Please revert this.

@thenbe

thenbe commented Jun 12, 2023

Copy link
Copy Markdown
Contributor

I was trying to understand why this PR is needed.

This is how I rendered components before this PR and how I still continue to do so. However, this PR caused a type issue that requires a workaround. I'm just wondering, what did we gain in return? What am I missing?

import { renderComponent } from '@tanstack/svelte-table';

const columns = [
	display({
		id: 'mail',
		cell: () => renderComponent(EmailColumn), // without props
		cell: () => renderComponent(EmailColumn, { myprop: 'foo' }), // with props (type-safe)
	}),
];

@KevinVandy

Copy link
Copy Markdown
Member

I've just been waiting for someone to make a PR to fix it correctly. If it is as simple as reverting this, we can.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants