Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-create the clients when they are updated via HMR #1221

Merged
merged 1 commit into from
May 16, 2024
Merged
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
19 changes: 18 additions & 1 deletion web/src/context/installer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,28 @@ function InstallerClientProvider({
return;
}

console.warn(`Failed to connect to D-Bus (attempt ${attempt + 1})`);
console.warn(`Failed to connect to Agama API (attempt ${attempt + 1})`);
await new Promise(resolve => setTimeout(resolve, interval));
setAttempt(attempt + 1);
};

// allow hot replacement for the clients code
if (module.hot) {
// if anything coming from `import ... from "~/client"` is updated then this hook is called
module.hot.accept("~/client", async function() {
console.log("[Agama HMR] A client module has been updated");

const updated_client = await createDefaultClient();
if (await updated_client.isConnected()) {
console.log("[Agama HMR] Using new clients");
setValue(updated_client);
} else {
console.warn("[Agama HMR] Updating clients failed, using full page reload");
window.location.reload();
}
});
}

if (!value) connectClient();
}, [setValue, value, setAttempt, attempt, interval]);

Expand Down
Loading