mirror of
https://github.com/Threnklyn/wg-ui.git
synced 2026-05-18 21:03:30 +02:00
ui: avoid "async race" with new client POST
The getClients() and POST request were being issued one after another (not waiting for the POST to return). This can cause the GET /clients to return the old list before the user config is updated. Waiting for the POST to return before retrieving the new client list fixes the race. This behavior can be reproduced by adding a time.Sleep(time.Second) to the CreateClient server handler.
This commit is contained in:
@@ -17,9 +17,10 @@
|
||||
async function handleNewClick(event) {
|
||||
const res = await fetch(clientsUrl, {
|
||||
method: "POST",
|
||||
}).then(getClients());
|
||||
});
|
||||
let newClient = await res.json();
|
||||
console.log("New client added", newClient);
|
||||
await getClients();
|
||||
}
|
||||
|
||||
onMount(getClients);
|
||||
|
||||
Reference in New Issue
Block a user