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

fix(http-server): append livereload to end of document; #79

Merged
merged 2 commits into from
Oct 31, 2021

Conversation

lukeed
Copy link
Contributor

@lukeed lukeed commented Oct 31, 2021

Scripts are still valid & will still execute, even if outside of the <html> tags. The browsers' HTML parsers are incredibly loose/forgiving haha

Here's a valid HTML document, which still logs to the console:

<html>
  <title>hello</title>
  <p>content</p>
</html>
<script defer>
  console.log('loaded')
</script>

Closes #70

@mrbbot
Copy link
Contributor

mrbbot commented Oct 31, 2021

Nice ✅, probably don't really need HTMLRewriter for this anymore if we're just appending to the end of the stream. 😅 Are there any scenarios where onDocument end is not the end of the stream? Could maybe just write the script before passThrough.end()?

@lukeed
Copy link
Contributor Author

lukeed commented Oct 31, 2021

Yeah, I don't think HTMLRewriter is needed at all anymore, but I felt bad removing it outright :D

@mrbbot mrbbot merged commit a3cd455 into cloudflare:v2 Oct 31, 2021
@lukeed lukeed deleted the fix/reload branch October 31, 2021 18:07
@mrbbot
Copy link
Contributor

mrbbot commented Oct 31, 2021

Hang on, just thought of an issue. If the Response headers include a Content-Length header, the live reload script won't be included. Actually this is a bug with HTMLRewriter too, if the transformed Response is a different size and Content-Length is wrong, the browser won't display the page correctly.

@lukeed
Copy link
Contributor Author

lukeed commented Oct 31, 2021

I noticed the same thing while playing with the rewriter in cf playground. Have a note to open an internal issue tomorrow

@mrbbot
Copy link
Contributor

mrbbot commented Oct 31, 2021

Oh, didn't realise it was an issue with the real implementation too. 😄

@lukeed
Copy link
Contributor Author

lukeed commented Oct 31, 2021

Oops – total brain fart. The CF playground implementation is okay – at least while returning rewriter.transform(res) directly. Because it's streamed, the transfer-encoding: chunked header is added and any content-length value is omitted, even if you try to force the wrong value: Playground

@mrbbot
Copy link
Contributor

mrbbot commented Oct 31, 2021

Ok, I'll fix that now in Miniflare's implementation 👍

@mrbbot
Copy link
Contributor

mrbbot commented Oct 31, 2021

Fixed in 3de7fd2 and 849938c 👍

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.

None yet

2 participants