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

A null key is cached instead of font-size on initial page load #109

Closed
rdipardo opened this issue Jun 26, 2022 · 1 comment
Closed

A null key is cached instead of font-size on initial page load #109

rdipardo opened this issue Jun 26, 2022 · 1 comment

Comments

@rdipardo
Copy link
Contributor

Describe the bug

On page load, core.js looks in local storage for a font size:

if (fontSizeInLocalStorage) {
var n = Number.parseInt(fontSizeInLocalStorage, 10);
if (n === fontSize) {
return;
}
updateFontSize(n);
} else {
localStorage.setItem(fontSizeInLocalStorage, fontSize);
}
})();

When storage is empty, a key of null is returned and then stored with the current font size value:

init-page-null-key

The null entry is never updated, because clicking the "Change font size" button creates a new, proper key:

post-toggle-key

To Reproduce

  1. Go to https://ankdev.me/clean-jsdoc-theme/v4/
  2. Open the Developer Tools panel (F12 or Ctrl+Shift+I
  3. Select the Application tab and inspect Local Storage for the https://ankdev.me domain
  4. A null key has the value 16

Expected behavior

A font-size key has the value 16

Screenshots

See description above

Desktop (please complete the following information):

  • OS: Linux 4.19.0-20-amd64 #1 SMP Debian 4.19.235-1 (2022-03-17) x86_64 GNU/Linux
  • Browser: Opera
  • Version: 88.0.4412.40

Additional context

This change will ensure the font size key is always a valid string:

--- a/static/scripts/core.js
+++ b/static/scripts/core.js
@@ -413,7 +413,7 @@ function updateFontSize(fontSize) {
     }
     updateFontSize(n);
   } else {
-    localStorage.setItem(fontSizeInLocalStorage, fontSize);
+    localStorage.setItem(fontSizeLocalStorageKey, fontSize);
   }
 })();
 
@ankitskvmdam
Copy link
Owner

Thanks, @rdipardo, it is beautiful that you have spotted this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants