diff --git a/src/LiveComponent/assets/dist/live_controller.js b/src/LiveComponent/assets/dist/live_controller.js index 7656af38a52..7cd308ecb2d 100644 --- a/src/LiveComponent/assets/dist/live_controller.js +++ b/src/LiveComponent/assets/dist/live_controller.js @@ -1946,7 +1946,6 @@ class Component { this.valueStore.flushDirtyPropsToPending(); this.isRequestPending = false; this.backendRequest.promise.then(async (response) => { - this.backendRequest = null; const backendResponse = new BackendResponse(response); const html = await backendResponse.getBody(); for (const input of Object.values(this.pendingFiles)) { @@ -1960,10 +1959,12 @@ class Component { if (controls.displayError) { this.renderError(html); } + this.backendRequest = null; thisPromiseResolve(backendResponse); return response; } this.processRerender(html, backendResponse); + this.backendRequest = null; thisPromiseResolve(backendResponse); if (this.isRequestPending) { this.isRequestPending = false; diff --git a/src/LiveComponent/assets/src/Component/index.ts b/src/LiveComponent/assets/src/Component/index.ts index 503379eb80d..49026af9f6c 100644 --- a/src/LiveComponent/assets/src/Component/index.ts +++ b/src/LiveComponent/assets/src/Component/index.ts @@ -390,7 +390,6 @@ export default class Component { this.isRequestPending = false; this.backendRequest.promise.then(async (response) => { - this.backendRequest = null; const backendResponse = new BackendResponse(response); const html = await backendResponse.getBody(); @@ -410,6 +409,7 @@ export default class Component { this.renderError(html); } + this.backendRequest = null; thisPromiseResolve(backendResponse); return response; @@ -418,6 +418,7 @@ export default class Component { this.processRerender(html, backendResponse); // finally resolve this promise + this.backendRequest = null; thisPromiseResolve(backendResponse); // do we already have another request pending? diff --git a/src/LiveComponent/assets/test/controller/render.test.ts b/src/LiveComponent/assets/test/controller/render.test.ts index cb93c578189..1ccc347a76f 100644 --- a/src/LiveComponent/assets/test/controller/render.test.ts +++ b/src/LiveComponent/assets/test/controller/render.test.ts @@ -329,6 +329,65 @@ describe('LiveController rendering Tests', () => { await waitFor(() => expect(test.element).toHaveTextContent('Title: "greetings to you"')); }); + it('waits for the rendering process of previous request to finish before starting a new one', async () => { + const test = await createTest({ + title: 'greetings', + contents: '', + }, (data: any) => ` +