-
Notifications
You must be signed in to change notification settings - Fork 231
fix(core): make Table column utilities callable from React Server Components #3466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
arham766
wants to merge
2
commits into
facebook:main
Choose a base branch
from
arham766:fix/table-column-helpers-rsc
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+8
−2
Open
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| --- | ||
| '@astryxdesign/core': patch | ||
| --- | ||
|
|
||
| [fix] Table: proportional() and pixel() no longer throw when called from a React Server Component. The Table barrel carried a 'use client' directive that marked the pure column utilities as client functions; the directive now lives only on the component modules, and Table.doc.mjs documents which parts of the data-driven API are server-safe (#3457) | ||
| @arham766 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| // Copyright (c) Meta Platforms, Inc. and affiliates. | ||
|
|
||
| /** | ||
| * @file Source invariants for the Table server-client boundary. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure this test is high value. Just making sure it works with a test plan is probably good enough for this fix! |
||
| * | ||
| * The Table barrel (index.ts) must stay free of 'use client' so the pure | ||
| * column utilities (proportional, pixel, generateColumns, paginateData) | ||
| * remain callable from React Server Components; a directive on the barrel | ||
| * marks them as client functions and they throw when called during a | ||
| * server render (#3457). The client boundary is carried by each component | ||
| * module instead, so this test pins both halves of that arrangement. | ||
| */ | ||
|
|
||
| import {describe, it, expect} from 'vitest'; | ||
| import * as fs from 'node:fs'; | ||
| import * as path from 'node:path'; | ||
| import {fileURLToPath} from 'node:url'; | ||
|
|
||
| const tableDir = path.dirname(fileURLToPath(import.meta.url)); | ||
|
|
||
| function hasUseClient(file: string): boolean { | ||
| const content = fs.readFileSync(path.join(tableDir, file), 'utf-8'); | ||
| return /^\s*['"]use client['"];\s*$/m.test(content); | ||
| } | ||
|
|
||
| describe('Table RSC boundary', () => { | ||
| it('keeps the barrel free of "use client" so column utilities stay server-safe', () => { | ||
| expect(hasUseClient('index.ts')).toBe(false); | ||
| expect(hasUseClient('columnUtils.ts')).toBe(false); | ||
| expect(hasUseClient('types.ts')).toBe(false); | ||
| }); | ||
|
|
||
| it('keeps the directive on the client component modules', () => { | ||
| expect(hasUseClient('Table.tsx')).toBe(true); | ||
| expect(hasUseClient('BaseTable.tsx')).toBe(true); | ||
| expect(hasUseClient('TableCell.tsx')).toBe(true); | ||
| expect(hasUseClient('TableContext.ts')).toBe(true); | ||
| }); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just removing use client is probably okay i don't think we need the comment