Skip to content

perf(table): only call once OnQuery when set ScrollMode to Virtual#8071

Merged
ArgoZhang merged 2 commits into
mainfrom
fix-table
May 31, 2026
Merged

perf(table): only call once OnQuery when set ScrollMode to Virtual#8071
ArgoZhang merged 2 commits into
mainfrom
fix-table

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented May 31, 2026

Link issues

fixes #8065

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Avoid duplicate data queries when using virtual scroll in the table component and ensure appropriate UI updates on initial render.

Bug Fixes:

  • Prevent multiple initial data queries when the table scroll mode is virtual, avoiding redundant OnQuery invocations.

Enhancements:

  • Trigger a simple state update instead of a full query on initial render when virtual scrolling is enabled to improve performance.

Copilot AI review requested due to automatic review settings May 31, 2026 06:11
@bb-auto bb-auto Bot added the bug Something isn't working label May 31, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 31, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts table query behavior to avoid duplicate data loading when using virtual scroll, by gating initial query execution based on scroll mode and tracking first-query state in the virtualized items provider.

Sequence diagram for table query behavior with virtual scroll

sequenceDiagram
    participant Table as Table
    participant Virtualize as Virtualize

    alt ScrollMode_None
        Table->>Table: OnAfterRenderAsync(firstRender)
        Table->>Table: QueryAsync(isInit true, pageIndex 1,
        Table->>Table: StateHasChanged()
    else ScrollMode_Virtual
        Table->>Table: OnAfterRenderAsync(firstRender)
        Table->>Table: StateHasChanged()
        Virtualize->>Table: LoadItems(request)
        Table->>Table: ToggleLoading(true)
        Table->>Table: QueryData(triggerByPagination false, firstQuery true)
        Table->>Table: ToggleLoading(false)
        Note right of Table: isFirstQuery set to false after first QueryData
    end
Loading

File-Level Changes

Change Details Files
Gate the initial OnQuery invocation in OnAfterRenderAsync based on scroll mode to avoid redundant queries with virtual scrolling enabled.
  • Wrap the initial QueryAsync invocation in a ScrollMode == None check so it only runs for non-virtual scroll tables
  • For non-None scroll modes, replace the initial query call with a StateHasChanged to refresh the component without querying
src/BootstrapBlazor/Components/Table/Table.razor.cs
Modify the virtualized items provider to only treat the first load as an initial query and subsequent loads as pagination-driven queries.
  • Introduce a private isFirstQuery flag to track whether the items provider is executing its first query
  • Pass triggerByPagination: false and firstQuery: isFirstQuery into QueryData to distinguish first load from later loads
  • Set isFirstQuery to false after the first QueryData call to prevent repeated first-query behavior
src/BootstrapBlazor/Components/Table/Table.razor.cs

Assessment against linked issues

Issue Objective Addressed Explanation
#8065 Ensure that when the table uses virtual scrolling (ScrollMode = Virtual), the data query callback (OnQueryAsync) is not invoked twice on initial render, but only once.

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@bb-auto bb-auto Bot added this to the v10.6.0 milestone May 31, 2026
Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've left some high level feedback:

  • The new isFirstQuery flag is never reset, so if the data source, filters, or ScrollMode change over the lifetime of the component, subsequent virtual-scroll sessions may incorrectly skip the 'first query' behavior; consider resetting it when relevant component state changes (e.g., data source or scroll mode changes, or on reinitialization).
  • In OnAfterRenderAsync, the new StateHasChanged() call in the ScrollMode != None branch can easily cause an extra render loop; if this is only needed on the initial render or under specific conditions, consider guarding it with firstRender or a more precise condition to avoid unnecessary re-renders.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `isFirstQuery` flag is never reset, so if the data source, filters, or `ScrollMode` change over the lifetime of the component, subsequent virtual-scroll sessions may incorrectly skip the 'first query' behavior; consider resetting it when relevant component state changes (e.g., data source or scroll mode changes, or on reinitialization).
- In `OnAfterRenderAsync`, the new `StateHasChanged()` call in the `ScrollMode != None` branch can easily cause an extra render loop; if this is only needed on the initial render or under specific conditions, consider guarding it with `firstRender` or a more precise condition to avoid unnecessary re-renders.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@ArgoZhang ArgoZhang merged commit cc9ac4f into main May 31, 2026
4 checks passed
@ArgoZhang ArgoZhang deleted the fix-table branch May 31, 2026 06:13
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 31, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (1a30a62) to head (2f6dda6).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #8071   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          766       766           
  Lines        34163     34171    +8     
  Branches      4699      4700    +1     
=========================================
+ Hits         34163     34171    +8     
Flag Coverage Δ
BB 100.00% <100.00%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(table): 表格开启虚拟滚动,数据加载问题

2 participants