[RFC Early Feedback] Require client directive for all framework components #67
Replies: 8 comments 21 replies
-
I actually really like the idea of requiring a hydration directive and adding a My main hesitation is defaulting to a build warning + The story of Astro so far has really leaned into the no JS by default idea, and I'd hate to lose that. If we throw a build error and require a client directive I think we're still true to that idea, but if the default behavior is to assume What if we added |
Beta Was this translation helpful? Give feedback.
-
I must say, I feel that if they user is using a ui framework then its a given that they are using that to augment their site with JS of whichever flavour. To default this would be somewhat breaking the 0kb shipped model. But that is somewhat subjective in its interpretation. |
Beta Was this translation helpful? Give feedback.
-
I would suggest the other way around. As a user, if I’m using a client-side framework, I’d prefer Astro respect my choice. If specifying a directive is important enough to require, then let’s embrace import assertions, and at least let devs write it once. ---
import Date from '../components/Date.js' assert { client: 'idle' }
---
I think only frameworks with limited support for islands benefit from this. React can fail managing independent, inter-connected components on a page, but it’s a purposeful design choice by React. Web Components support independent, inter-connected components on a page. When we can render Web Components on a page, we will not want to dupe client directives all over the page. |
Beta Was this translation helpful? Give feedback.
-
This is definitely spicy. There's a flip-side to the problem that this seeks to solve. Case A
If we implement this suggestion then we have the opposite problem. Case B
When we created Astro we decided that Case A was preferable. I'd hate to see us backtrack from that. We fixed a footgun, adding JS when it is not needed, and I think this reverses that. |
Beta Was this translation helpful? Give feedback.
-
This is one thing I don't understand about this proposal as it also says:
So a client directive is not required in this proposal, and the default is to include JavaScript unless specified not to. |
Beta Was this translation helpful? Give feedback.
-
Crazier spicy take - could this be an interactive dev warning in the browser? During |
Beta Was this translation helpful? Give feedback.
-
I think a really powerful part of Astro for someone coming from Nextjs for example, is that they can take all of their components, copy them over to their Astro site, and get a no-js website that works out of the box with no client side directive additions example: https://www.youtube.com/watch?v=LAVZyaFG73g where Chris Coyier (@chriscoyier) and Dave Rupert (@davatron5000) transition https://github.com/CSS-Tricks/serverless over to Astro via CSS-Tricks/serverless#182 If we remove |
Beta Was this translation helpful? Give feedback.
-
From aboveBackgroundUsers continue to have trouble when they use a framework component without a client directive and expect it to be interactive and clicking on the page, seeing nothing happen. This is a feature of Astro, not a bug, and a part of our "easy to do the right thing" mentality. But, it's still confusing when it happens to you, and feels like Astro is broken. The result is a poor user experience for new users and pro users alike. ProposalGive a friendly warning if one is not given, and default to Hey there 👋🏽 I don't know the status of this, but it would be really helpful if you can include a warning that a JS Framework Component is not loading correctly because a client directive was not set. If this is a major lift, maybe you can create a ESLint plugin to optimize an Astro project, similar to Next.js and default to Great work on the framework, and thanks again! |
Beta Was this translation helpful? Give feedback.
-
A couple of discussions & threads have recently connected in my brain, and I want to throw out an idea that may be a way to address all of them at once.
I know that this idea probably sounds spicy but give it some thought before responding:
Background
Proposal
I want to throw this idea out for feedback:
client:*
directive on every framework component.client:idle
.client:none
directive to opt-in to current default behavior.I think this addresses all of the issues above:
Thoughts? Too wild? Not wild enough?
I would love to hear from some power users here on whether they use static,
client:none
framework components often.Beta Was this translation helpful? Give feedback.
All reactions