Exploration around supporting no JS #484
Replies: 2 comments 2 replies
-
Wow, really awesome! I think whenever possible, if we can support shipping less javascript, we should. It’s something I love about https://kit.svelte.dev/ (also a Vite app!), Remix. The closer to fundamentals, the better; older stuff ironically helps us future proof, it helps cross compatibility, it can positively impact SEO and accessibility, and it decreases maintenance. That said — there are a lot of times we’ll need to ship JS for interactivity, and we shouldn’t break our backs to not do that. I'd enthusiastically support all of these ideas, so long as the implementation doesn't significantly increase the lift, or de-prioritize critical merchant DX features/critical shopping features. For instance: |
Beta Was this translation helpful? Give feedback.
-
I might be misunderstanding but I think that, in order to support No-JS, the developer needs to make things thoughtfully because there won't be any hydration:
Therefore, this might require more work than only relying on API routes 🤔 In any case, the Form component is a good idea if we want to support this use case. For the API, what about |
Beta Was this translation helpful? Give feedback.
-
Hydrogen should provide primitive features to progressively enhance a web experience, even supporting a browser that has JavaScript disabled. This RFC explores some ideas on how that might look in Hydrogen.
Embrace Native Forms
<form>
element, provide a<Form>
wrapper. This wrapper will only execute when JavaScript is enabled, and will prevent the default form submission, and instead manually construct a fetch request.Example
Preview video: https://screenshot.click/19-20-5btql-o8cvg.mp4
Preview branch: https://github.com/Shopify/hydrogen/tree/bl-nojs
Questions and Ideas
useRefresh()
hook.<Form>
fetch vs a vanilla<form action>
POST. If so, then the server could respond with a redirect (for<form>
) or a RSC response (for fetch).fetch
withnew FormData()
is a multipart form request, and undici doesn't support multipart form requests. Open issue for it to be added: Implement multipart parsing nodejs/undici#974serverState
, both with and without JS?Beta Was this translation helpful? Give feedback.
All reactions