fix(svelte-table): delegate context setting to App* components during initialization #6622
main fromrefs/pull/6622/head·opened Summary#
In @tanstack/svelte-table, createAppTable previously defined AppTable, AppCell, AppHeader, and AppFooter wrappers as plain functions that invoked setContext() directly before invoking the underlying Svelte component (AppCellSvelte, AppHeaderSvelte, AppTableSvelte).
Because setContext was called in the wrapper function closure before the Svelte component mounted, it ran in the parent component's context. When cells or headers are rendered dynamically after the parent component has already initialized (for example, when toggling column visibility via column.toggleVisibility() or with Svelte 5 async mode enabled), Svelte throws:
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
Changes#
- Forward
contextKeyand the respective entity (cell,header,table) as props intoAppCellSvelte,AppHeaderSvelte, andAppTableSvelte. - Invoke
setContextinside the<script lang="ts">ofAppCell.svelte,AppHeader.svelte, andAppTable.svelteduring their own component initialization. - Remove
setContextcalls from the outer wrapper function closure increateTableHook.svelte.ts. - Add changeset for
@tanstack/svelte-table.
Summary by CodeRabbit#
- Bug Fixes
- Fixed an initialization issue that could cause a Svelte context error when using table components. Context is now set during component initialization, while existing rendering behavior remains unchanged. This improves reliability for tables, cells, headers, and footers that rely on shared context.
- 1
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
- Configuration used: Repository: TanStack/table/.coderabbit.yaml
- Review profile: CHILL
- Plan: Advanced
- Run ID:
5b2487f2-1659-404b-8ef4-1d4b60d77939
📥 Commits
Reviewing files that changed from the base of the PR and between 6aa0d74946b393f4f316085998bb6ec31c2ef593 and 57041b272bfcd1773625bc76c008dbc0a2bc3002.
📒 Files selected for processing (5)
.changeset/fix-svelte-table-app-context-init.mdpackages/svelte-table/src/AppCell.sveltepackages/svelte-table/src/AppHeader.sveltepackages/svelte-table/src/AppTable.sveltepackages/svelte-table/src/createTableHook.svelte.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
📝 Walkthrough
Walkthrough#
The Svelte table wrappers now pass context keys and values to App components. Those components register the context with
setContextduring initialization.Changes#
Svelte context initialization
Layer / File(s) Summary Register context in App components
packages/svelte-table/src/AppCell.svelte,packages/svelte-table/src/AppHeader.svelte,packages/svelte-table/src/AppTable.svelteAppCellandAppHeaderaccept an optionalcontextKeyand register their cell or header when it is provided.AppTableaccepts an optionalcontextKeyandtablevalue, then registers the table when the key is provided.Pass context props from wrappers
packages/svelte-table/src/createTableHook.svelte.ts,.changeset/fix-svelte-table-app-context-init.mdThe wrapper callbacks pass context keys to the App components instead of calling setContext.AppTablealso receives the table instance. TheAppFootercallback passesheaderContextKeytoAppHeaderSvelte. The changeset describes the initialization fix.Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix
Suggested reviewers:
kevinvandyMerge Risk: ⚪ Minimal · up to
57041The context change preserves the existing wrapper contracts while moving registration into component initialization. No concrete merge-blocking risk is evident.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation Title check ✅ Passed The title clearly and concisely describes the main change: moving context setting to App* components during initialization. Description check ✅ Passed The description explains the problem, motivation, implementation, and changeset. It includes the main Changes content but omits the template's Checklist and Release Impact sections. Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 2 functions across 1 files. (4 skipped: 4 … Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request. ✨ Finishing Touches
🧪 Generate unit tests (beta)
- Create a new PR
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment `@coderabbitai help` to get the list of available commands.Closing in favor of the earlier open pull request https://github.com/TanStack/table/pull/6618.
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: 57041b272bfcd1773625bc76c008dbc0a2bc3002
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR