Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion framework/core/js/src/forum/states/DiscussionListState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ export default class DiscussionListState<P extends DiscussionListParams = Discus
}

requestParams(): PaginatedListRequestParams {
// `filter` is cloned so extenders mutating it don't write back into
// `this.params.filter` — that leak trips `paramsChanged()` on the next
// mount and wipes the paginated cache (see #4583).
const params = {
include: ['user', 'lastPostedUser'],
filter: this.params.filter || {},
filter: { ...this.params.filter },
sort: this.currentSort(),
};

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import bootstrapForum from '@flarum/jest-config/src/bootstrap/forum';
import DiscussionListState from '../../../../src/forum/states/DiscussionListState';

beforeAll(() => bootstrapForum());

describe('DiscussionListState', () => {
describe('requestParams', () => {
// Regression test for #4583.
//
// Extenders (tags, subscriptions, …) mutate `params.filter` inside a
// `requestParams` extender callback. If `requestParams` returns
// `this.params.filter` by reference, those mutations leak back into the
// stored state — and on the next mount `paramsChanged()` falsely reports
// a change, wiping the paginated cache and resetting the list to page 1.
test('does not leak this.params.filter to callers', () => {
const state = new DiscussionListState({ filter: { tag: 'foo' } } as any);

const out = state.requestParams() as { filter: Record<string, string> };
out.filter.injectedByExtender = 'yes';

expect((state as any).params.filter).toEqual({ tag: 'foo' });
expect((state as any).params.filter.injectedByExtender).toBeUndefined();
});
});
});
Loading