Skip to content

Conversation

@adxy
Copy link
Contributor

@adxy adxy commented Oct 22, 2025

Problem

Live reload JavaScript was appearing as malformed text (.close(); window.location.reload();) in generated HTML files when using --serve flag.
Screenshot 2025-10-23 at 12 02 06 AM

Root Cause

The live reload script was injected before the second template pass in FlushFile(). Go's template parser interpreted socket.close() as template syntax, evaluating the undefined socket variable to empty string, leaving only .close() as literal text.

Solution

  • Removed live reload injection from layout template preprocessing
  • Added _getLiveReloadScript() helper function
  • Inject live reload script after final template execution (lines 726-730)
  • Added f.Truncate(0) to ensure clean file rewrite

Result

JavaScript is written as raw text after template processing completes, preventing the parser from mangling it.

@barelyhuman
Copy link
Owner

Sadly, this is not just for the script.

The compilation of markdown -> HTML -> Inject -> HTML for most of everything will cause this mangling.

A very simple way to reproduce this is to add an indentation in the markdown while writing HTML tags. It's a thing with the markdown parser which I've been side stepping on my website for a while but haven't fixed it on alvu since not a lot of people use it.

The PR here will only partially fix it, there's still a chance of something getting mangled during actual builds when the serve flag is off.

I'll keep the PR open and work on replacing the flow of how markdown files get turned to HTML so we can avoid these kind of issues altogether

@barelyhuman
Copy link
Owner

Got most of it fixed in #9 but the added modularity makes it slower when compared to the current implementation and I've not been able to find time to work on it again.

@adxy
Copy link
Contributor Author

adxy commented Oct 23, 2025

Cool, I'll take a deeper look at this as well.

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

Successfully merging this pull request may close these issues.

2 participants