five-server icon indicating copy to clipboard operation
five-server copied to clipboard

hot reload does not work if the HTML does not include <body>

Open trusktr opened this issue 1 year ago • 1 comments

version 0.4.0

Describe the bug

For example, given an HTML file like this,

<style>h1 {color: blue}</style>
<h1>hello</h1>

the server will not reload when changes are made. Instead, the file has to be written like this:

<body>
  <style>h1 {color: blue}</style>
  <h1>hello</h1>
</body>

I think the issue is here:

https://github.com/yandeu/five-server/blob/95711266d5e5b7d95eae6107c1c4d716223cd9a8/src/middleware/injectCode.ts#L38-L51

Looks like if it does not find </head>, </html>, or </body>, then it will not inject code.

I think it should have a last resort which is to simply append the injected script tag to the end of the file (this means it will implicitly be at the end of the <body> that the browser will generate).

trusktr avatar Feb 05 '25 23:02 trusktr

Pull request testing and working:

  • https://github.com/yandeu/five-server/pull/154

I tested it with my project, and now all my pages work without having to wrap them with <head>, <html>, or <body>.

trusktr avatar Feb 05 '25 23:02 trusktr