diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0c10e1d9..4dd3daa4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -1,42 +1,53 @@ name: ci + +on: + workflow_dispatch: + inputs: + tag: + description: override release tag + required: false + push: + branches: ['main', 'alpha', 'beta'] + concurrency: - group: publish-${{ github.github.base_ref }} + group: ${{ github.workflow }}-${{ github.event.number || github.ref }} cancel-in-progress: true + env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} -on: - push: - branches: - - 'main' - - 'beta' + jobs: test-and-publish: - name: 'Test & Publish' + name: Test & Publish + if: github.repository == 'TanStack/virtual' runs-on: ubuntu-latest steps: - - name: Checkout Repo - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v4 with: fetch-depth: '0' - - name: Setup Pnpm - uses: pnpm/action-setup@v2.2.4 + - name: Setup pnpm + uses: pnpm/action-setup@v2 with: - version: 7 + version: 8 - name: Setup Node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: - node-version: 16.19.0 - cache: 'pnpm' + node-version-file: .nvmrc + cache: pnpm - name: Install dependencies - run: pnpm --filter "./packages/**" --prefer-offline install --no-frozen-lockfile - - name: Publish + run: pnpm install --frozen-lockfile --prefer-offline + - name: Run Tests + run: pnpm run test:ci +- name: Publish run: | git config --global user.name 'Tanner Linsley' git config --global user.email 'tannerlinsley@users.noreply.github.com' npm config set '//registry.npmjs.org/:_authToken' "${NPM_TOKEN}" - pnpm cipublish + pnpm run cipublish env: GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} GH_TOKEN: ${{ secrets.GH_TOKEN }} + NPM_TOKEN: ${{ secrets.NPM_TOKEN }} NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} + TAG: ${{ inputs.tag }} diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 67aa0661..70a0723a 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -1,27 +1,42 @@ name: pr -on: [pull_request] + +on: + pull_request: + paths-ignore: + - 'docs/**' + - 'media/**' + - '**/*.md' + +concurrency: + group: ${{ github.workflow }}-${{ github.event.number || github.ref }} + cancel-in-progress: true + env: - NPM_TOKEN: ${{ secrets.NPM_TOKEN }} NX_CLOUD_ACCESS_TOKEN: ${{ secrets.NX_CLOUD_ACCESS_TOKEN }} + jobs: test: - name: 'Test' + name: Test runs-on: ubuntu-latest steps: - - name: Checkout Repo - uses: actions/checkout@v3 + - name: Checkout + uses: actions/checkout@v4 with: - fetch-depth: '0' - - name: Setup Pnpm - uses: pnpm/action-setup@v2.2.4 + fetch-depth: 0 + - name: Setup pnpm + uses: pnpm/action-setup@v2 with: - version: 7 + version: 8 - name: Setup Node - uses: actions/setup-node@v3 + uses: actions/setup-node@v4 with: - node-version: 16.19.0 - cache: 'pnpm' + node-version-file: .nvmrc + cache: pnpm - name: Install dependencies - run: pnpm --filter "./packages/**" --prefer-offline install --no-frozen-lockfile - - name: Build & Test - run: npx nx run-many --targets=test,build --projects=@tanstack/* --exclude=@tanstack/react-start + run: pnpm install --frozen-lockfile --prefer-offline + - name: Get base and head commits for `nx affected` + uses: nrwl/nx-set-shas@v3 + with: + main-branch-name: 'main' + - name: Run Checks + run: pnpm run test:pr diff --git a/.gitignore b/.gitignore index ed2e5d21..a1ae46d7 100644 --- a/.gitignore +++ b/.gitignore @@ -24,8 +24,6 @@ coverage .env.test.local .env.production.local .next -.nx/cache -.pnpm-store npm-debug.log* yarn-debug.log* @@ -39,6 +37,9 @@ stats.html *.log .DS_Store -node_modules .cache -dist +.nx/cache +.pnpm-store + +vite.config.js.timestamp-* +vite.config.ts.timestamp-* diff --git a/.nx/workflows/dynamic-changesets.yaml b/.nx/workflows/dynamic-changesets.yaml new file mode 100644 index 00000000..29c58231 --- /dev/null +++ b/.nx/workflows/dynamic-changesets.yaml @@ -0,0 +1,4 @@ +distribute-on: + small-changeset: 8 linux-medium-js + medium-changeset: 10 linux-medium-js + large-changeset: 12 linux-medium-js diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 00000000..6534da93 --- /dev/null +++ b/.prettierignore @@ -0,0 +1,9 @@ +**/.next +**/.nx/cache +**/.svelte-kit +**/build +**/coverage +**/dist +**/docs +**/codemods/**/__testfixtures__ +pnpm-lock.yaml diff --git a/examples/react/dynamic/index.html b/examples/react/dynamic/index.html index 22f6ccfe..84b7eb68 100644 --- a/examples/react/dynamic/index.html +++ b/examples/react/dynamic/index.html @@ -1,4 +1,4 @@ - +
diff --git a/examples/react/dynamic/vite.config.js b/examples/react/dynamic/vite.config.js index b1b5f91e..5a33944a 100644 --- a/examples/react/dynamic/vite.config.js +++ b/examples/react/dynamic/vite.config.js @@ -3,5 +3,5 @@ import react from '@vitejs/plugin-react' // https://vitejs.dev/config/ export default defineConfig({ - plugins: [react()] + plugins: [react()], }) diff --git a/examples/react/fixed/index.html b/examples/react/fixed/index.html index 22f6ccfe..84b7eb68 100644 --- a/examples/react/fixed/index.html +++ b/examples/react/fixed/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/react/fixed/src/main.tsx b/examples/react/fixed/src/main.tsx index c8bb5901..a67ed5bf 100644 --- a/examples/react/fixed/src/main.tsx +++ b/examples/react/fixed/src/main.tsx @@ -189,8 +189,8 @@ function GridVirtualizerFixed() { ? 'ListItemOdd' : 'ListItemEven' : virtualRow.index % 2 - ? 'ListItemOdd' - : 'ListItemEven' + ? 'ListItemOdd' + : 'ListItemEven' } style={{ position: 'absolute', diff --git a/examples/react/infinite-scroll/index.html b/examples/react/infinite-scroll/index.html index dfcecb0b..3fc40c93 100644 --- a/examples/react/infinite-scroll/index.html +++ b/examples/react/infinite-scroll/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/react/padding/index.html b/examples/react/padding/index.html index dfcecb0b..3fc40c93 100644 --- a/examples/react/padding/index.html +++ b/examples/react/padding/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/react/padding/src/main.tsx b/examples/react/padding/src/main.tsx index dab696f4..59cf86f6 100644 --- a/examples/react/padding/src/main.tsx +++ b/examples/react/padding/src/main.tsx @@ -211,8 +211,8 @@ function GridVirtualizerDynamic({ rows, columns }) { ? 'ListItemOdd' : 'ListItemEven' : virtualRow.index % 2 - ? 'ListItemOdd' - : 'ListItemEven' + ? 'ListItemOdd' + : 'ListItemEven' } style={{ position: 'absolute', diff --git a/examples/react/scroll-padding/index.html b/examples/react/scroll-padding/index.html index dfcecb0b..3fc40c93 100644 --- a/examples/react/scroll-padding/index.html +++ b/examples/react/scroll-padding/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/react/smooth-scroll/index.html b/examples/react/smooth-scroll/index.html index dfcecb0b..3fc40c93 100644 --- a/examples/react/smooth-scroll/index.html +++ b/examples/react/smooth-scroll/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/react/sticky/index.html b/examples/react/sticky/index.html index dfcecb0b..3fc40c93 100644 --- a/examples/react/sticky/index.html +++ b/examples/react/sticky/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/react/table/index.html b/examples/react/table/index.html index ec41bbdd..ba530a2c 100644 --- a/examples/react/table/index.html +++ b/examples/react/table/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/react/table/vite.config.js b/examples/react/table/vite.config.js index b1b5f91e..5a33944a 100644 --- a/examples/react/table/vite.config.js +++ b/examples/react/table/vite.config.js @@ -3,5 +3,5 @@ import react from '@vitejs/plugin-react' // https://vitejs.dev/config/ export default defineConfig({ - plugins: [react()] + plugins: [react()], }) diff --git a/examples/react/variable/index.html b/examples/react/variable/index.html index dfcecb0b..3fc40c93 100644 --- a/examples/react/variable/index.html +++ b/examples/react/variable/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/react/variable/src/main.tsx b/examples/react/variable/src/main.tsx index c4b04bac..b9e2bb26 100644 --- a/examples/react/variable/src/main.tsx +++ b/examples/react/variable/src/main.tsx @@ -204,8 +204,8 @@ function GridVirtualizerVariable({ rows, columns }) { ? 'ListItemOdd' : 'ListItemEven' : virtualRow.index % 2 - ? 'ListItemOdd' - : 'ListItemEven' + ? 'ListItemOdd' + : 'ListItemEven' } style={{ position: 'absolute', diff --git a/examples/react/window/index.html b/examples/react/window/index.html index 22f6ccfe..84b7eb68 100644 --- a/examples/react/window/index.html +++ b/examples/react/window/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/svelte/dynamic/index.html b/examples/svelte/dynamic/index.html index 40f96ce2..eaa17316 100644 --- a/examples/svelte/dynamic/index.html +++ b/examples/svelte/dynamic/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/svelte/fixed/index.html b/examples/svelte/fixed/index.html index 40f96ce2..eaa17316 100644 --- a/examples/svelte/fixed/index.html +++ b/examples/svelte/fixed/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/svelte/infinite-scroll/index.html b/examples/svelte/infinite-scroll/index.html index 40f96ce2..eaa17316 100644 --- a/examples/svelte/infinite-scroll/index.html +++ b/examples/svelte/infinite-scroll/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/svelte/smooth-scroll/index.html b/examples/svelte/smooth-scroll/index.html index 40f96ce2..eaa17316 100644 --- a/examples/svelte/smooth-scroll/index.html +++ b/examples/svelte/smooth-scroll/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/svelte/sticky/index.html b/examples/svelte/sticky/index.html index 40f96ce2..eaa17316 100644 --- a/examples/svelte/sticky/index.html +++ b/examples/svelte/sticky/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/svelte/table/index.html b/examples/svelte/table/index.html index 40f96ce2..eaa17316 100644 --- a/examples/svelte/table/index.html +++ b/examples/svelte/table/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/vue/dynamic/index.html b/examples/vue/dynamic/index.html index 143557b5..dde16aaf 100644 --- a/examples/vue/dynamic/index.html +++ b/examples/vue/dynamic/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/vue/fixed/index.html b/examples/vue/fixed/index.html index 143557b5..dde16aaf 100644 --- a/examples/vue/fixed/index.html +++ b/examples/vue/fixed/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/vue/fixed/src/components/GridVirtualizerFixed.vue b/examples/vue/fixed/src/components/GridVirtualizerFixed.vue index 24828241..72d04069 100644 --- a/examples/vue/fixed/src/components/GridVirtualizerFixed.vue +++ b/examples/vue/fixed/src/components/GridVirtualizerFixed.vue @@ -21,8 +21,8 @@ ? 'ListItemOdd' : 'ListItemEven' : virtualRow.index % 2 - ? 'ListItemOdd' - : 'ListItemEven' + ? 'ListItemOdd' + : 'ListItemEven' " :style="{ position: 'absolute', diff --git a/examples/vue/infinite-scroll/index.html b/examples/vue/infinite-scroll/index.html index 143557b5..dde16aaf 100644 --- a/examples/vue/infinite-scroll/index.html +++ b/examples/vue/infinite-scroll/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/vue/padding/index.html b/examples/vue/padding/index.html index 143557b5..dde16aaf 100644 --- a/examples/vue/padding/index.html +++ b/examples/vue/padding/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/vue/padding/src/components/GridVirtualizerPadding.vue b/examples/vue/padding/src/components/GridVirtualizerPadding.vue index 7b58a0dc..8d029fa3 100644 --- a/examples/vue/padding/src/components/GridVirtualizerPadding.vue +++ b/examples/vue/padding/src/components/GridVirtualizerPadding.vue @@ -32,8 +32,8 @@ ? 'ListItemOdd' : 'ListItemEven' : virtualRow.index % 2 - ? 'ListItemOdd' - : 'ListItemEven' + ? 'ListItemOdd' + : 'ListItemEven' " :style="{ position: 'absolute', diff --git a/examples/vue/scroll-padding/index.html b/examples/vue/scroll-padding/index.html index 143557b5..dde16aaf 100644 --- a/examples/vue/scroll-padding/index.html +++ b/examples/vue/scroll-padding/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/vue/smooth-scroll/index.html b/examples/vue/smooth-scroll/index.html index 143557b5..dde16aaf 100644 --- a/examples/vue/smooth-scroll/index.html +++ b/examples/vue/smooth-scroll/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/vue/sticky/index.html b/examples/vue/sticky/index.html index 143557b5..dde16aaf 100644 --- a/examples/vue/sticky/index.html +++ b/examples/vue/sticky/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/vue/table/index.html b/examples/vue/table/index.html index 143557b5..dde16aaf 100644 --- a/examples/vue/table/index.html +++ b/examples/vue/table/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/vue/table/src/style.css b/examples/vue/table/src/style.css index 305725d4..7f784706 100644 --- a/examples/vue/table/src/style.css +++ b/examples/vue/table/src/style.css @@ -28,4 +28,4 @@ body { .text-left { text-align: left; -} \ No newline at end of file +} diff --git a/examples/vue/variable/index.html b/examples/vue/variable/index.html index 143557b5..dde16aaf 100644 --- a/examples/vue/variable/index.html +++ b/examples/vue/variable/index.html @@ -1,4 +1,4 @@ - + diff --git a/examples/vue/variable/src/components/GridVirtualizerVariable.vue b/examples/vue/variable/src/components/GridVirtualizerVariable.vue index 01992f9f..1a70b227 100644 --- a/examples/vue/variable/src/components/GridVirtualizerVariable.vue +++ b/examples/vue/variable/src/components/GridVirtualizerVariable.vue @@ -21,8 +21,8 @@ ? 'ListItemOdd' : 'ListItemEven' : virtualRow.index % 2 - ? 'ListItemOdd' - : 'ListItemEven' + ? 'ListItemOdd' + : 'ListItemEven' " :style="{ position: 'absolute', diff --git a/package.json b/package.json index 8d21a322..8d2ed36d 100644 --- a/package.json +++ b/package.json @@ -11,8 +11,8 @@ "clean": "pnpm --filter \"./packages/**\" run clean", "preinstall": "node -e \"if(process.env.CI == 'true') {console.log('Skipping preinstall...'); process.exit(1)}\" || npx -y only-allow pnpm", "test": "pnpm run test:ci", - "test:pr": "nx affected --targets=test:format,test:lib,test:types,test:build,build", - "test:ci": "nx run-many --targets=test:format,test:lib,test:types,test:build,build", + "test:pr": "nx affected --targets=test:format,test:lib,test:types,test:build,build --exclude=examples/**", + "test:ci": "nx run-many --targets=test:format,test:lib,test:types,test:build,build --exclude=examples/**", "test:format": "pnpm run prettier --check", "test:lib": "nx affected --target=test:lib --exclude=examples/**", "test:lib:dev": "pnpm run test:lib && nx watch --all -- pnpm run test:lib", @@ -48,7 +48,7 @@ "concurrently": "^7.1.0", "jest": "^27.5.1", "nx": "^18.0.4", - "prettier": "^2.8.0", + "prettier": "^3.2.5", "react": "^18.2.0", "react-dom": "^18.2.0", "react-virtual": "^2.10.4", diff --git a/packages/virtual-core/src/index.ts b/packages/virtual-core/src/index.ts index 5cc027e7..47505759 100644 --- a/packages/virtual-core/src/index.ts +++ b/packages/virtual-core/src/index.ts @@ -502,15 +502,13 @@ export class Virtualizer< } return furthestMeasurements.size === this.options.lanes - ? Array.from(furthestMeasurements.values()).sort( - (a, b) => { - if (a.end === b.end) { - return a.index - b.index; - } - - return a.end - b.end; - }, - )[0] + ? Array.from(furthestMeasurements.values()).sort((a, b) => { + if (a.end === b.end) { + return a.index - b.index + } + + return a.end - b.end + })[0] : undefined } @@ -659,9 +657,7 @@ export class Virtualizer< const delta = size - itemSize if (delta !== 0) { - if ( - item.start < this.scrollOffset + this.scrollAdjustments - ) { + if (item.start < this.scrollOffset + this.scrollAdjustments) { if (process.env.NODE_ENV !== 'production' && this.options.debug) { console.info('correction', delta) } @@ -868,22 +864,23 @@ export class Virtualizer< } getTotalSize = () => { - const measurements = this.getMeasurements(); + const measurements = this.getMeasurements() - let end: number; + let end: number // If there are no measurements, set the end to paddingStart if (measurements.length === 0) { - end = this.options.paddingStart; + end = this.options.paddingStart } else { // If lanes is 1, use the last measurement's end, otherwise find the maximum end value among all measurements - end = this.options.lanes === 1 - ? (measurements[measurements.length - 1]?.end ?? 0) - : Math.max(...measurements.slice(-this.options.lanes).map((m) => m.end)); + end = + this.options.lanes === 1 + ? measurements[measurements.length - 1]?.end ?? 0 + : Math.max( + ...measurements.slice(-this.options.lanes).map((m) => m.end), + ) } - return end - - this.options.scrollMargin + - this.options.paddingEnd + return end - this.options.scrollMargin + this.options.paddingEnd } private _scrollToOffset = ( diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index bc6339bf..2e749a2e 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -51,8 +51,8 @@ importers: specifier: ^18.0.4 version: 18.0.4 prettier: - specifier: ^2.8.0 - version: 2.8.8 + specifier: ^3.2.5 + version: 3.2.5 react: specifier: ^18.2.0 version: 18.2.0 @@ -6460,9 +6460,9 @@ packages: picocolors: 1.0.0 source-map-js: 1.0.2 - /prettier@2.8.8: - resolution: {integrity: sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==} - engines: {node: '>=10.13.0'} + /prettier@3.2.5: + resolution: {integrity: sha512-3/GWa9aOC0YeD7LUfvOG2NiDyhOWRvt1k+rcKhOuYnMY24iiCphgneUfJDyFXd6rZCAnuLBv6UeAULtrhT/F4A==} + engines: {node: '>=14'} hasBin: true dev: true diff --git a/scripts/publish.js b/scripts/publish.js index fc31c27c..ba818b50 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -12,4 +12,4 @@ await publish({ ghToken: process.env.GH_TOKEN, }) -process.exit(0) \ No newline at end of file +process.exit(0)