Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[svelte] createTableHook: App* wrappers call setContext in the parent's component context (set_context_after_init when showing a column)

オープン
#6,614 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
typescript
領域
frontend

調査の方向性

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.

索引モデルが issue の本文から書いたものです。

説明

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

  1. Create a table with createTableHook / createAppTable where one column is hidden (initialState: { columnVisibility: { age: false } }), and render cells with <table.AppCell {cell}>.
  2. Show the column: table.getColumn('age').toggleVisibility().
  3. 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)

https://svelte.dev/playground#H4sIAAAAAAAAA3VUTW-bQBD9K1N6MEgYVLXqgWJUq1KUS3tool5CFK2XMayy3kW74zop4r9Xu2Bj7OTCx-zMe2_eDHSBYjsMsuCeqTti_Bnu2UYicIOM0D_fav0MFumJa0X4Qk9sS2iehBIUxAExIQ9CVUG2ZdJiHGyFRBtkD11Ar61DdoEgPvKs2zaxf1GSi22YxbfinkmRDbIgt9yIlopSlSR2rTYE3aW6GMg93iCjvUEbA9dyv1N_hBUbIQW9jifQw9boHSy-E1PWdZsOlEtfv_hWKkfDtbITy7ptPVE8vf_w8LcoWzTQw-pST9g5mJK2o6Bsri_s3hcYxa60j2ZS-Dnf6m0doS-ZFViXe5aSjOHwYZA3O2Oco7XahAs3kEUMHTTIKjQZLH65yFHbu3Wsvihb11PV47wj78d5K967o2-jzpGuYsQyGDWX1IET6OArtoiB1ZjB56_Qx9cJkqljxpdPp4zH8e4WWDB5R4wwg-uZuJiv9YsN_QjgZ5On01qq_MNyCXeNPghVAzUIjagqVCPg2KMFhQfIfeOJmx1KWVjw3xJQIyxwvWu1QkUwKhP_sEpguSxKlW_2RFqBVlwK_rzqwghWxWBjUiMNmzDMIEpI17XEqZMw6ot7H4MyWNdYBnk6AA76T6L8FPynNsSKwamcNrp6LU4Gf0TGm4n8tz781BXKMEqMPlhgFow-QGj0IRFV1B_rHJApprcTkkuskbxgic4ZG0YOhqOUELrrBdAAdu4ldC6tL-Y5jsIq0bZIwBshK4Mq5JdIA1pV5Dy5kfjyG1WFxpOvOt5DWuQpVdfI6Yh8qSudD3nWcOoaPnckPbNkdpqnk-sjpFuE9GpY7ieMLxRkZPbYP_b_AZTC5qvTBQAA

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.
主要言語
TypeScript
スター
28.5k
フォーク
3.6k
平均マージ
19時間 40分
マージ済み PR(30日)
8

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

TanStack/table のほかの issue

TanStack/table の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。