Skip to content

feat: add state invalidation to BasePaginator class#1734

Open
arnautov-anton wants to merge 1 commit intomasterfrom
feat/base-paginator-state-invalidation
Open

feat: add state invalidation to BasePaginator class#1734
arnautov-anton wants to merge 1 commit intomasterfrom
feat/base-paginator-state-invalidation

Conversation

@arnautov-anton
Copy link
Copy Markdown
Contributor

@arnautov-anton arnautov-anton commented May 5, 2026

Description of the changes, What, Why and How?

Adds state invalidation logic to a BasePaginator class, adjusts types. Super-simplified react-query feature (invalidateQueries).

Ref: GetStream/stream-chat-react#3173

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 5, 2026

Size Change: +350 B (+0.09%)

Total Size: 381 kB

📦 View Changed
Filename Size Change
dist/cjs/index.browser.js 127 kB +116 B (+0.09%)
dist/cjs/index.node.js 128 kB +114 B (+0.09%)
dist/esm/index.mjs 126 kB +120 B (+0.1%)

compressed-size-action

@arnautov-anton arnautov-anton force-pushed the feat/base-paginator-state-invalidation branch 3 times, most recently from 2312c6f to 836b577 Compare May 5, 2026 20:08
@arnautov-anton arnautov-anton force-pushed the feat/base-paginator-state-invalidation branch from 836b577 to bd6d38e Compare May 5, 2026 20:10
@arnautov-anton arnautov-anton force-pushed the feat/base-paginator-state-invalidation branch from bd6d38e to 2e509fb Compare May 5, 2026 20:10
if (!this.canExecuteQuery(direction)) return;
const isFirstPage = typeof this.items === 'undefined';
if (isFirstPage) {
this.state.next(this.getStateBeforeFirstQuery());
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Removing this is potentially breaking

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

As this is setting state before the query is executed. This is a hook that can be used by integrators to adjust the state before the first query.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

State before the first query should always be initialState unless invalidated. When invalidated and re-fetched, the state is kept until there's something to replace it with to prevent the data -> no data -> new data UI blinking.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ok, then we should also remove getStateBeforeFirstQuery method, because in this PR it does not make anymore sense - it is called before the first query but not applied to the state before the first query.

Comment thread src/pagination/BasePaginator.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants