transform/livereloadinject: Don't use document.write to inject livereload
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 31 Jan 2020 07:02:53 +0000 (08:02 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 31 Jan 2020 07:02:53 +0000 (08:02 +0100)
I suspect the person who originally implemented it saw examples using location.host etc. to build the URL.

We have all that information ready at build (static) time.

Fixes #6507

transform/livereloadinject/livereloadinject.go
transform/livereloadinject/livereloadinject_test.go

index f34b4fb5903dd8a31e598826eb061802d6f79c77..896dcab4e371f4bb8acf21f5d22d53c06ab94a29 100644 (file)
@@ -59,7 +59,7 @@ func New(port int) transform.Transformer {
                        return err
                }
 
-               script := []byte(fmt.Sprintf(`<script data-no-instant>document.write('<script src="/livereload.js?port=%d&mindelay=10&v=2"></' + 'script>')</script>`, port))
+               script := []byte(fmt.Sprintf(`<script src="/livereload.js?port=%d&mindelay=10&v=2" data-no-instant></script>`, port))
 
                i := idx
                if match.appendScript {
index 4dd256bb042df83091c46a50b57a9b634c98d60f..ea1b3aa653e7008966b55cdd176611588e3363c8 100644 (file)
@@ -25,7 +25,7 @@ import (
 func TestLiveReloadInject(t *testing.T) {
        c := qt.New(t)
 
-       expectBase := `<script data-no-instant>document.write('<script src="/livereload.js?port=1313&mindelay=10&v=2"></' + 'script>')</script>`
+       expectBase := `<script src="/livereload.js?port=1313&mindelay=10&v=2" data-no-instant></script>`
        apply := func(s string) string {
                out := new(bytes.Buffer)
                in := strings.NewReader(s)