Fiber version
v2.0.2
Issue description
Continue from https://github.com/gofiber/fiber/issues/814, which were having the problem of
html/template: cannot Clone "layouts/main" after it has executed
html/template, andHowever, the reload was not necessary before, and it only works for simple demo examples. I.e., my demo is working after the fix, while my real application is still suffering from the issue.
Here are the details:
Code snippet
package main
import "github.com/gofiber/fiber/v2"
func main() {
app := fiber.New()
// Steps to reproduce
app.Get("/layout", func(c *fiber.Ctx) error {
// Render index within layouts/main
return c.Render("index", fiber.Map{
"Title": "Hello, World!",
}, "layouts/main")
})
log.Fatal(app.Listen(":3000"))
}
I've setup a new demo at https://gitlab.com/suntong/template-html/,
Here are the test logs:
$ cat go.mod
module template-html
go 1.14
require (
github.com/gofiber/fiber/v2 v2.0.2
github.com/gofiber/template v1.6.2
)
# Start my real application
$ curl http://localhost:5858/layout
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,500|Poppins:400,500,600,700|Roboto:400,500"
rel="stylesheet" />
<link href="https://cdn.materialdesignicons.com/3.0.39/css/materialdesignicons.min.css" rel="stylesheet" />
<link id="sleek-css" rel="stylesheet" href="assets/css/sleek.min.css" />
<title>Hello, World! - </title>
</head>
<body id="body">
<h1>Hello, World!</h1>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="assets/plugins/slimscrollbar/jquery.slimscroll.min.js"></script>
<script src="assets/js/sleek.bundle.js"></script>
</body>
</html>
# Start my demo
$ curl http://localhost:3000/layout
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link href="https://fonts.googleapis.com/css?family=Montserrat:400,500|Poppins:400,500,600,700|Roboto:400,500"
rel="stylesheet" />
<link href="https://cdn.materialdesignicons.com/3.0.39/css/materialdesignicons.min.css" rel="stylesheet" />
<link id="sleek-css" rel="stylesheet" href="assets/css/sleek.min.css" />
<title>Hello, World! - </title>
</head>
<body id="body">
<h1>Hello, World!</h1>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="assets/plugins/slimscrollbar/jquery.slimscroll.min.js"></script>
<script src="assets/js/sleek.bundle.js"></script>
</body>
</html>
# repeat
$ curl http://localhost:5858/layout
html/template: cannot Clone "layouts/main" after it has executed
$ curl -s http://localhost:3000/layout | tail -6
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="assets/plugins/slimscrollbar/jquery.slimscroll.min.js"></script>
<script src="assets/js/sleek.bundle.js"></script>
</body>
</html>
. . .
$ curl -s http://localhost:3000/layout | tail -6
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="assets/plugins/slimscrollbar/jquery.slimscroll.min.js"></script>
<script src="assets/js/sleek.bundle.js"></script>
</body>
</html>
i.e., my demo can sustain the repeated requests while my real application cannot.
Again, everything about the html template handing is the same between my demo and my real application, and even the middlewares. So I'm suspecting that any other mildly complicated template/html based application would suffer from the same issue, caused by the same problem that needs to reload the template engine. If someone has to have my real application to duplicate the issue, please give me your gitlab id so that I can add you to my private project.
Thanks
i have the same issue
im looking into it!
from my observations the issue does not seem to be with gofiber/template/html.
i went to take a deeper dive into the html/template package
in the template.go file after i removed the check for that highlighted src.EscapeErr it started to work expectedly.

so i believe this issue should be moved to golang/go/issues

after i further modified the template.go file and got it to print out the new error message it says:
html/template: cannot Clone "layouts/main" because of an escape error: "template escaped correctly"
i think removing this from the golang/go/html/template/template.go and refactoring the code would fix the issue

The question is why is an escapeErr set in the first place, maybe this is something we can solve on our end.
The question is why is an
escapeErrset in the first place, maybe this is something we can solve on our end.
Yep, totally agree.
Giving the fact that V1 has no problems at all all the time and V2 suddenly has such problem, I'd highly suspect that the issue is V2 related, not the Go html/template package.
The question is why is an
escapeErrset in the first place, maybe this is something we can solve on our end.Yep, totally agree.
Giving the fact that V1 has no problems at all all the time and V2 suddenly has such problem, I'd highly suspect that the issue is V2 related, not the Go html/template package.
Yes it seems like it is actually an issue with V2, because the the template.go file has not been drastically modified in the past 2 years.
But maybe someone should refactor that file?
I have some time tomorrow to debug this issue, I will post updates here 馃憤
Hello, so far I'm only getting this error if
*Engine.Reload == false
i propose that we have a fork of the orginal golang/go project where we try to improve it and then later on when it is stable we will merge it back in to the go's official repo.
Have you tried turn on *Engine.Reload and leave Go html/template package unchanged @anton7r?
Have you tried turn on
*Engine.Reloadand leave Go html/template package unchanged @anton7r?
yes, but thats not really viable to use on production because it will slow down rendering performance quite a bit
Ah, gotya. yeah, make sense.
I'm still trying to fix the issue, but no luck so far 馃槙馃樀
edit: found the problem, expect a PR soon. ( keep you updated )
@suntong, @anton7r this problem is fixed in v1.6.3, feel free to re-open if you encounter problems 馃憤
Most helpful comment
@suntong, @anton7r this problem is fixed in v1.6.3, feel free to re-open if you encounter problems 馃憤