[svelte] createTableHook: App* wrappers call setContext in the parent's component context (set_context_after_init when showing a column)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 68/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- typescript
- Lĩnh vực
- frontend
Hướng nghiên cứu
Start by reading createTableHook.svelte.js and the AppCell.svelte, AppHeader.svelte, and AppTable.svelte components named in the issue; check how the wrappers and components set context. Reproduce the error in the linked Svelte playground by showing the hidden Age column. Done means newly created cells, headers, and tables set context in their own component initialization, and toggling the column no longer errors.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
TanStack Table version
@tanstack/svelte-table v9.2.5 (the same code is in v9.2.6)
Framework/Library version
Svelte v5.57.1, with compilerOptions.experimental.async: true
Describe the bug and the steps to reproduce it
With createTableHook, any <table.AppCell> / <table.AppHeader> that is created after the component using it has initialized throws set_context_after_init, and the cells don't render. The most common trigger is showing a hidden column; it also affects anything else that creates new cells later.
Svelte error: set_context_after_init
`setContext` must be called when a component first initializes, not in a subsequent effect or after an `await` expression
at setContext
at AppCell (createTableHook.svelte.js)
Steps (see the playground below):
- Create a table with
createTableHook/createAppTablewhere one column is hidden (initialState: { columnVisibility: { age: false } }), and render cells with<table.AppCell {cell}>. - Show the column:
table.getColumn('age').toggleVisibility(). - The error is thrown and the new column's cells aren't rendered.
Cause: createAppTable builds the App* wrappers as plain functions that call setContext and then call the real component:
const AppCell = ((internal, { children, cell }) => {
setContext(cellContextKey, cell);
return AppCellSvelte(internal, { cell, cellComponents: cellComponentsWithFlexRender, children });
});
setContext runs before AppCellSvelte has pushed its own component context, so it writes into the parent's context (the component that renders <table.AppCell>). Svelte's async mode validates that setContext only runs while a component initializes. That holds during the parent's first render, but not for cells created later, e.g. when a column is shown. Without async mode it doesn't throw, but cells/headers still get written into the parent's context map rather than their own. The same applies to AppHeader, AppFooter and AppTable.
Possible fix, which I'm using as a local patch: let the App*Svelte components set the context themselves, during their own initialization, and have the wrappers only pass props:
// createTableHook.svelte.js
- const AppCell = ((internal, { children, cell }) => {
- setContext(cellContextKey, cell);
- return AppCellSvelte(internal, {
- cell,
- cellComponents: cellComponentsWithFlexRender,
- children,
- });
- });
+ const AppCell = ((internal, { children, cell }) => AppCellSvelte(internal, {
+ cell,
+ cellComponents: cellComponentsWithFlexRender,
+ contextKey: cellContextKey,
+ children,
+ }));
<!-- AppCell.svelte -->
<script lang="ts">
- import type { Snippet } from 'svelte'
+ import { setContext, type Snippet } from 'svelte'
...
- let { children, cell, cellComponents }: Props = $props()
+ let { children, cell, cellComponents, contextKey }: Props = $props()
+
+ setContext(contextKey, cell)
</script>
…and the same for AppHeader / AppFooter (AppHeader.svelte) and AppTable (AppTable.svelte, which would receive table as a prop). With that patch, showing/hiding columns, paging, sorting and filtering work without errors, and useCellContext / useHeaderContext / useTableContext return the right instances.
Your Minimal, Reproducible Example - (Sandbox Highly Recommended)
Click Toggle "Age": the error appears in the console and the "Age" cells don't render.
Screenshots or Videos (Optional)
No response
Do you intend to try to help solve this bug with your own PR?
Yes, I think I know how to fix it and will discuss it in the comments of this issue
Terms & Code of Conduct
- I agree to follow this project's Code of Conduct
- I understand that if my bug cannot be reliable reproduced in a debuggable environment, it will probably not be fixed and this issue may even be closed.
- Ngôn ngữ chính
- TypeScript
- Star
- 28.5k
- Fork
- 3.6k
- Merge trung bình
- 19 giờ 40 phút
- Pull request đã merge (30 ngày)
- 8
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của TanStack/table
-
Issue template renders `react-table`, not `TanStack/table`Có thể đã có người làm @vishruthasgowda đã nhận 13 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 78/100
TanStack/table#6595 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 38/100
TanStack/table#6601 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Cast required to access custom options when defining a custom plugin/featureCó thể đã có người làm @sorena-paydar đã nhận 14 ngày trước. Đang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
-
`aggregatedCell` not typed against bound `cellComponents` in `createAppColumnHelper`Có thể đã có người làm @cpruijsen đã nhận 25 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
TanStack/table#6577 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của TanStack/table
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 83/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Signals (Failure Detector): a tool call and its own execution are reported as a repeated callĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 85/100
platformatic/mcp#208 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
🐛 bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
margelo/react-native-vision-camera#4211 ·
Maintainer thường phản hồi trong vòng 4 ngày