Skip to content

Commit

Permalink
Improve performance and fix title update issue
Browse files Browse the repository at this point in the history
- Increased debounce delay for saving content to local storage to 1000ms.
- Removed debounce from title updates
  • Loading branch information
mhersson committed Jan 26, 2025
1 parent 0ca0b19 commit cf0dd41
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

SHELL=bash

VERSION="v0.8.3"
VERSION="v0.8.4"

# make will interpret non-option arguments in the command line as targets.
# This turns them into do-nothing targets, so make won't complain:
Expand Down
12 changes: 4 additions & 8 deletions internal/previewserver/web/ws.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
document.addEventListener("DOMContentLoaded", () => {
const ws = new WebSocket("ws://localhost:%d/ws");

const DEBOUNCE_DELAY = 200;
const DEBOUNCE_DELAY = 1000;
let debounceTimeout;
let isReloading = false;

Expand All @@ -12,19 +12,15 @@ document.addEventListener("DOMContentLoaded", () => {
};
}

const updateTitle = debounce((title) => {
document.title = title;
const saveContentToLocalStorage = debounce((renderedHtml) => {
localStorage.setItem("savedContent", renderedHtml);
}, DEBOUNCE_DELAY);

function updateContent(renderedHtml) {
document.body.innerHTML = `<div id="content">${renderedHtml}</div>`;
// console.log(renderedHtml);
}

const saveContentToLocalStorage = debounce((renderedHtml) => {
localStorage.setItem("savedContent", renderedHtml);
}, DEBOUNCE_DELAY);

const renderMermaid = async () => {
const mermaidElements = document.querySelectorAll(".language-mermaid");
if (mermaidElements.length > 0) {
Expand Down Expand Up @@ -65,7 +61,7 @@ document.addEventListener("DOMContentLoaded", () => {
const title = "mpls - " + response.Title;

if (title !== document.title) {
updateTitle(title);
document.title = title;
}

updateContent(renderedHtml);
Expand Down

0 comments on commit cf0dd41

Please sign in to comment.