mirror of
https://github.com/Studio-Saelix/sencho.git
synced 2026-08-07 01:14:14 +00:00
fix(stacks): close double-click race in create handler (F-2)
The setState-based busy guard could race a second click that landed before React committed the disabled state, so two POSTs got dispatched when a user double-clicked Create. The new useRef-based check is read and written synchronously inside the handler so a re-entrant invocation bails before issuing a second fetch. The accompanying E2E (`create dialog: double-clicking Create fires only one POST`) was also hanging to its 30s test timeout: the second click's locator resolution could outlive the dialog when the first POST resolved quickly, so Playwright waited for `[role="dialog"]` to reappear. Both clicks now fire in the same microtask via Promise.all with a 1s timeout on the second click so the locator-resolution path fails fast instead of hanging the test.
This commit is contained in:
+9
-3
@@ -72,9 +72,15 @@ test.describe('Stack management', () => {
|
||||
await page.locator('#create-stack-name').fill(stackName);
|
||||
|
||||
const createBtn = page.locator('[role="dialog"]').getByRole('button', { name: /^Create/ });
|
||||
// Rapid double-click; the busy guard must reject the second click synchronously.
|
||||
await createBtn.click();
|
||||
await createBtn.click({ force: true }).catch(() => { /* second click may land on disabled btn */ });
|
||||
// Fire both clicks in the same microtask via Promise.all so the second
|
||||
// dispatches without an awaited gap that would let React commit the
|
||||
// disabled state in between. The 1s timeout on the second click prevents
|
||||
// a 30s hang on locator resolution if the first POST has already closed
|
||||
// the dialog.
|
||||
await Promise.all([
|
||||
createBtn.click(),
|
||||
createBtn.click({ force: true, timeout: 1_000 }).catch(() => undefined),
|
||||
]);
|
||||
|
||||
await expect(page.getByRole('dialog')).toBeHidden({ timeout: 8_000 });
|
||||
await expect(page.getByText(`Stack "${stackName}" created.`)).toBeVisible({ timeout: 5_000 });
|
||||
|
||||
Reference in New Issue
Block a user