Skip to content
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

fix(table-core): Avoid process not defined in environments not setting a process variable #5373

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/table-core/src/core/column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function createColumn<TData extends RowData, TValue>(

for (const key of accessorKey.split('.')) {
result = result?.[key]
if (process.env.NODE_ENV !== 'production' && result === undefined) {
if (typeof process !== "undefined" && process.env.NODE_ENV !== 'production' && result === undefined) {
console.warn(
`"${key}" in deeply nested key "${accessorKey}" returned undefined.`
)
Expand All @@ -112,7 +112,7 @@ export function createColumn<TData extends RowData, TValue>(
}

if (!id) {
if (process.env.NODE_ENV !== 'production') {
if (typeof process !== "undefined" && process.env.NODE_ENV !== 'production') {
throw new Error(
resolvedColumnDef.accessorFn
? `Columns require an id when using an accessorFn`
Expand Down
4 changes: 2 additions & 2 deletions packages/table-core/src/core/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ export function createTable<TData extends RowData>(
if (!row) {
row = table.getCoreRowModel().rowsById[id]
if (!row) {
if (process.env.NODE_ENV !== 'production') {
if (typeof process !== "undefined" && process.env.NODE_ENV !== 'production') {
throw new Error(`getRow could not find row with ID: ${id}`)
}
throw new Error()
Expand Down Expand Up @@ -498,7 +498,7 @@ export function createTable<TData extends RowData>(
getColumn: columnId => {
const column = table._getAllFlatColumnsById()[columnId]

if (process.env.NODE_ENV !== 'production' && !column) {
if (typeof process !== "undefined" && process.env.NODE_ENV !== 'production' && !column) {
console.error(`[Table] Column with id '${columnId}' does not exist.`)
}

Expand Down
5 changes: 4 additions & 1 deletion packages/table-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,10 @@ export function getMemoOptions(
) {
return {
debug: () => tableOptions?.debugAll ?? tableOptions[debugLevel],
key: process.env.NODE_ENV === 'development' && key,
key:
typeof process !== "undefined"
? process.env.NODE_ENV === "development" && key
: !key,
onChange,
}
}
2 changes: 1 addition & 1 deletion packages/table-core/src/utils/getCoreRowModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function getCoreRowModel<TData extends RowData>(): (
for (let i = 0; i < originalRows.length; i++) {
// This could be an expensive check at scale, so we should move it somewhere else, but where?
// if (!id) {
// if (process.env.NODE_ENV !== 'production') {
// if (typeof process !== "undefined" && process.env.NODE_ENV !== 'production') {
// throw new Error(`getRowId expected an ID, but got ${id}`)
// }
// }
Expand Down
2 changes: 1 addition & 1 deletion packages/table-core/src/utils/getFilteredRowModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function getFilteredRowModel<TData extends RowData>(): (
const filterFn = column.getFilterFn()

if (!filterFn) {
if (process.env.NODE_ENV !== 'production') {
if (typeof process !== "undefined" && process.env.NODE_ENV !== 'production') {
console.warn(
`Could not find a valid 'column.filterFn' for column with the ID: ${column.id}.`
)
Expand Down