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

Flash of Unstyled Content #123

Open
pixel-dust-dev opened this issue Apr 20, 2021 · 2 comments
Open

Flash of Unstyled Content #123

pixel-dust-dev opened this issue Apr 20, 2021 · 2 comments

Comments

@pixel-dust-dev
Copy link

I'm using this to encrypt a Hugo made static site.

I get a consistent FOUC when navigating through the site pages.

Are there any proposed solutions to this?

@pixel-dust-dev
Copy link
Author

I ended up solving the issue by modifying the password_template.html as follows:

      function decryptAndReplace(pass) {
        const encryptedMsg = "{encrypted}";
        const encryptedHMAC = encryptedMsg.substring(0, 64);
        const encryptedHTML = encryptedMsg.substring(64);
        const decryptedHMAC = CryptoJS.HmacSHA256(
          encryptedHTML,
          CryptoJS.SHA256(pass).toString()
        ).toString();

        if (decryptedHMAC !== encryptedHMAC) {
          alert("Bad passphrase!");
          sessionStorage.removeItem(STORAGE_KEY);
          return;
        }

        // Save for the session
        sessionStorage.setItem(STORAGE_KEY, pass);

        const plainHTML = decryptContent(encryptedHTML, pass);

        document.write("<div id='loading'>Loading</div>");

        document.write(plainHTML);
        document.close();
        var loadingElem = document. getElementById("loading"); 
        loadingElem. remove();
      }

I create a "loading" div, then remove it after the rest of the document is written.

Kinda hacky, but it works for now.

@robinmoisson
Copy link
Owner

Hey @pixel-dust-dev, thank you for reporting and providing a suggested fix. Sorry for the long delay in getting to it. Do you still have an example of a file that produces a FOUC?

I opened a PR that should fix the password prompt flash when using the "Remember-me" in #142, but your reported issue is different and I haven't seen the issue on the files I use staticrypt on, which might be too simple.

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

No branches or pull requests

2 participants