Hanami: Asset helpers don't work on status pages. Intended?

Created on 6 Jun 2017  路  9Comments  路  Source: hanami/hanami

Maybe it's not a bug, but I would like to clarify: is it intended that for default status pages like 404.hml, 500.html - there's no option to use asset helpers (like asset_path, image, javascript, etc)?

Here is the related part of Hanami code, just for simplicity:
https://github.com/hanami/hanami/blob/master/lib/hanami/rendering_policy.rb#L54-L70

discussion for-future-consideration

Most helpful comment

I disagree @mereghost, I think we should have asset helpers for error pages (and layouts)

These past few years, a lot of websites have made their error pages evolve to become less frightening for users and to still feel like you're in the website.

There's no need to have an empty page for a 404 (or even a 500+ in most cases), you can have your navigation and lead the (otherwise lost) user back to your website.

Not having asset helpers means that you can't properly put assets on the page and won't be able to make it evolve like other parts of your website...

All 9 comments

IIRC most error pages end up being treated by Rack directly (or by the web server in case of 500+ errors), so I'm not sure we should have helpers working on error pages at all.

WDYT @hanami/core ?

I disagree @mereghost, I think we should have asset helpers for error pages (and layouts)

These past few years, a lot of websites have made their error pages evolve to become less frightening for users and to still feel like you're in the website.

There's no need to have an empty page for a 404 (or even a 500+ in most cases), you can have your navigation and lead the (otherwise lost) user back to your website.

Not having asset helpers means that you can't properly put assets on the page and won't be able to make it evolve like other parts of your website...

I absolutely agree with @TiteiKo. Any professional website should have decent error pages.
Most users will have some navigational component in their application layout and will want to render it or a minimal version of it when errors occur.

In theory the application layout could be the culprit for the occurrence of an error and in that case we'd be in deep s*. But I'd argue that it would be the responsibility of the developer to prevent such things from being possible, e.g., by using minimal layouts for error pages.

@TiteiKo I'm not against it, but having the application stack render an error page could lead us down a rabbit hole, specially if the application stack isn't working at all.

Static assets like error pages usually are served directly by the web server, with css and images that can be used when the application stack isn't even running at all, at least that's how we usually did. This does not bar you to having nice-ish error pages, just the way you design it and implement it.

(BTW the example linked above is from the company I work for. :P)

What about allowing user to use asset helpers on 404 for ex., but make those static pages compilable, so everything is wrapped into single html document in production?

Compiling the error page is a great idea.

Compiling static pages sounds good, if that's simple enough.

Otherwise, I think we should allow asset helpers on these pages, but also have a backup 500 page, in-case any of those break?

I'd prefer compiling the error pages over having a backup version of the 500 page.

Maybe the compiled error page can have a _default_ value before it's changed, but having two is not good in my opinion.

If all the CSS and JS and images are inlined into the HTML (with an asset rake task) then it should be servable by, for example, NGi袠X, regardless of any application errors. So in effect, the error pages _themselves_ become assets.

I agree that this should be implemented, but it isn't possible to do it correctly right now.

Assets settings

Assets have application based separated settings.

Given two apps web and admin inside a project I can reference <%= stylesheet "foo" %> from both the apps and Hanami will resolve for me the correct path: "/assets/foo.css" and "/assets/admin/foo.css", respectively.

Error pages

Multiple apps can have their own error pages: eg. apps/web/templates/404.html.erb and apps/admin/templates/404.html.erb.

However, the rendering of the error pages is delegated to Hanami::Views::Default at the project level.

If from both my 404 pages I do: <%= stylesheet "not-found.css" %>, the referenced CSS will be for both the apps: "/assets/not-found.css", which is wrong. Because for the admin app, it should link to "/assets/admin/not-found.css".

Conclusion

Adding this feature would introduce an inconsistency between how the assets are referenced from "regular" templates and how they're referenced from error templates.

A potential solution can be to move the assets settings to the project level. This will be the goal of hanami-assets 2.0.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Defman21 picture Defman21  路  7Comments

duykhoa picture duykhoa  路  6Comments

mdesantis picture mdesantis  路  8Comments

vlad-at-work picture vlad-at-work  路  7Comments

prio101 picture prio101  路  3Comments