fiber icon indicating copy to clipboard operation
fiber copied to clipboard

Reload views?

Open mrusme opened this issue 1 month ago • 8 comments

I've beein going through the Fiber code and stumbled upon the following line:

https://github.com/gofiber/fiber/blob/aaad4cf56e004d1453e41f766db74afe14739214/app.go#L1226C30-L1226C34

I was wondering if there are any side-effects that would prevent a call to app.config.Views.Load() from being made public via an app.ReloadViews() wrapper (or similar)?

The reason I'm asking is because I'm looking for a way to reload the whole views directory from disk without restarting the whole app.

mrusme avatar Nov 17 '25 15:11 mrusme

Wow, that was quick! Thank you @ReneWerner87 and @gaby. :-)

mrusme avatar Nov 18 '25 13:11 mrusme

Wow, that was quick! Thank you @ReneWerner87 and @gaby. :-)

😎😎😎

gaby avatar Nov 18 '25 13:11 gaby

I have tested this implementation, however, it doesn't appear to be working in my case. I have detailed the issue here.

mrusme avatar Nov 20 '25 12:11 mrusme

@mrusme I'm not sure if that's the correct way to use it. Can you try adding a handler /reload and calling it via fsnotify then in that handler run c.app.ReloadViews() ?

gaby avatar Nov 20 '25 12:11 gaby

Actually what you have makes sense, I'm just not sure if you have a pointer to app or not from the example you provided.

gaby avatar Nov 20 '25 12:11 gaby

Also, try visiting the site in a private tab, maybe the browser is caching the html

gaby avatar Nov 20 '25 12:11 gaby

Can you try adding a handler /reload and calling it via fsnotify then in that handler run c.app.ReloadViews() ?

Good suggestion! I added the following to my existing handler:

func (r *Route) Index(c fiber.Ctx) error {
	err := c.App().ReloadViews()
	r.Runtime.Error("error", err)
	return c.Render("views/root", fiber.Map{
		"Page": page.New(r.Runtime, c, "Root"),
	}, "views/layouts/base")
}

I am updating views/root.html and keep refreshing that route. Sadly the content doesn't change. I ruled out browser side caching as well. The Error output shows that err is null all the time.

mrusme avatar Nov 20 '25 14:11 mrusme

@mrusme Thanks, will investigate

gaby avatar Nov 22 '25 13:11 gaby