diff --git a/fetch-remote.sh b/fetch-remote.sh new file mode 100755 index 0000000000..ae4912e760 --- /dev/null +++ b/fetch-remote.sh @@ -0,0 +1,36 @@ +#!/bin/bash + +# --- Configuration --- +# Change this to 'origin' if your target beta branch is hosted there instead of 'upstream' +REMOTE="upstream" +TARGET_BRANCH="beta" +# --------------------- + +echo "Fetching latest changes from $REMOTE..." +git fetch $REMOTE + +# 1. Remember the branch you are currently working on +CURRENT_BRANCH=$(git branch --show-current) + +# 2. Switch to the beta branch +echo "Switching to $TARGET_BRANCH..." +git checkout $TARGET_BRANCH + +# 3. Fast-forward the local beta branch to match the remote +echo "Updating local $TARGET_BRANCH with $REMOTE/$TARGET_BRANCH..." +if git merge --ff-only $REMOTE/$TARGET_BRANCH; then + echo "✅ $TARGET_BRANCH successfully updated." +else + echo "❌ Error: Could not fast-forward. Do you have accidental local commits on $TARGET_BRANCH?" + # If this fails, you can force it to exactly match the remote by replacing the merge command with: + # git reset --hard $REMOTE/$TARGET_BRANCH + exit 1 +fi + +# 4. Switch back to your working branch (if you weren't already on beta) +if [ "$CURRENT_BRANCH" != "$TARGET_BRANCH" ]; then + echo "Switching back to your working branch: $CURRENT_BRANCH..." + git checkout "$CURRENT_BRANCH" +fi + +echo "Done!" \ No newline at end of file diff --git a/packages/react-table/package.json b/packages/react-table/package.json index 938f7be3f4..e09d298c05 100644 --- a/packages/react-table/package.json +++ b/packages/react-table/package.json @@ -63,8 +63,7 @@ "build": "tsdown" }, "dependencies": { - "@tanstack/react-store": "^0.11.0", - "@tanstack/table-core": "workspace:*" + "@tanstack/react-store": "^0.11.0" }, "devDependencies": { "@eslint-react/eslint-plugin": "^5.9.2", @@ -75,6 +74,7 @@ "react": "^19.2.7" }, "peerDependencies": { + "@tanstack/table-core": "workspace:*", "react": ">=18" } } diff --git a/packages/table-core/src/core/columns/coreColumnsFeature.ts b/packages/table-core/src/core/columns/coreColumnsFeature.ts index f21a2b3bfc..7bfaf9af44 100644 --- a/packages/table-core/src/core/columns/coreColumnsFeature.ts +++ b/packages/table-core/src/core/columns/coreColumnsFeature.ts @@ -7,6 +7,7 @@ import { table_getAllFlatColumnsById, table_getAllLeafColumns, table_getAllLeafColumnsById, + table_getCachedColumn, table_getColumn, table_getDefaultColumnDef, } from './coreColumnsFeature.utils' @@ -68,6 +69,9 @@ export const coreColumnsFeature: TableFeature = { table_getColumn: { fn: (columnId) => table_getColumn(table, columnId), }, + table_getCachedColumn: { + fn: (columnId) => table_getCachedColumn(table, columnId), + }, }) }, } diff --git a/packages/table-core/src/core/columns/coreColumnsFeature.types.ts b/packages/table-core/src/core/columns/coreColumnsFeature.types.ts index 2cd8780410..db5931629d 100644 --- a/packages/table-core/src/core/columns/coreColumnsFeature.types.ts +++ b/packages/table-core/src/core/columns/coreColumnsFeature.types.ts @@ -105,4 +105,8 @@ export interface Table_Columns< * Returns a single column by its ID. */ getColumn: (columnId: string) => Column | undefined + /** + * Returns a single column by its ID, but cached via WeakMap. + */ + getCachedColumn: (columnId: string) => Column | undefined } diff --git a/packages/table-core/src/core/columns/coreColumnsFeature.utils.ts b/packages/table-core/src/core/columns/coreColumnsFeature.utils.ts index 2fae8a1fd7..20e2b2e755 100644 --- a/packages/table-core/src/core/columns/coreColumnsFeature.utils.ts +++ b/packages/table-core/src/core/columns/coreColumnsFeature.utils.ts @@ -273,3 +273,23 @@ export function table_getColumn< return column } + +export function table_getCachedColumn< + TFeatures extends TableFeatures, + TData extends RowData, +>( + table: Table_Internal, + columnId: string, +): Column | undefined { + const columnDefs = table.options.columns + const cache = table._columnCache; + + let columnsById = cache.get(columnDefs) + + if (!columnsById) { + columnsById = table.getAllFlatColumnsById() + cache.set(columnDefs, columnsById) + } + + return columnsById[columnId] +} \ No newline at end of file diff --git a/packages/table-core/src/core/table/constructTable.ts b/packages/table-core/src/core/table/constructTable.ts index c4f10f0ed5..0c1047c344 100644 --- a/packages/table-core/src/core/table/constructTable.ts +++ b/packages/table-core/src/core/table/constructTable.ts @@ -63,6 +63,8 @@ export function constructTable< _rowModels: {}, _rowModelFns: { aggregationFns, filterFns, sortFns }, baseAtoms: {}, + // Import diffs will make updating this hell -> any + _columnCache: new WeakMap(), atoms: {}, } as unknown as Table_Internal diff --git a/packages/table-core/src/types/Table.ts b/packages/table-core/src/types/Table.ts index 829b657344..b8e9eaab84 100644 --- a/packages/table-core/src/types/Table.ts +++ b/packages/table-core/src/types/Table.ts @@ -113,4 +113,5 @@ export interface Table_Internal< baseAtoms: BaseAtoms & BaseAtoms_All atoms: Atoms & Atoms_All store: ReadonlyStore> & ReadonlyStore + _columnCache: WeakMap }