Skip to content

Commit 7d36e11

Browse files
radimvaculikclaude
andauthored
Fix: Prevent AJAX requests from modifying browser history (#1210) (#1237)
AJAX requests no longer modify the browser's history by default, preventing duplicate requests when users refresh the page after an AJAX operation. Changes: - Modified RequestParams to accept optional options parameter - Updated NajaAjax.request() to set history: false by default - Allows overriding history behavior if needed via options 🤖 Generated with Claude Code Co-authored-by: Claude <noreply@anthropic.com>
1 parent 5d3883b commit 7d36e11

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

assets/ajax/naja.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ export class NajaAjax<C extends Naja = Naja, G extends Datagrid = Datagrid> exte
118118
}
119119

120120
async request<D = {}, P = DatagridPayload>(args: RequestParams<D>): Promise<P> {
121-
return await this.client.makeRequest(args.method, args.url, args.data) as P;
121+
const options = { history: false, ...args.options };
122+
return await this.client.makeRequest(args.method, args.url, args.data ?? null, options) as P;
122123
}
123124

124125
async submitForm<E extends HTMLFormElement = HTMLFormElement, P = Payload>(element: E): Promise<P> {

assets/types/ajax.d.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export interface BaseRequestParams {
77
}
88

99
export interface RequestParams<D = any> extends BaseRequestParams {
10-
data: D;
10+
data?: D;
11+
options?: Record<string, any>;
1112
}
1213

1314
export interface DatagridPayload {

0 commit comments

Comments
 (0)