Import Assertions for Components, Assets, and Client Directives #69
Replies: 3 comments 6 replies
-
I really do think that this set of proposals helps to solidify alot of the concerns that were raised in the #67. Restating the concerns that were raised in rfc #67 ,
Use cases 3 and 4 are unfortunate circumstances where the intended design of the system has not been met fully with the consumer intuition of using the system. Causing this fall in UI component usage in Astro, and or providing a slightly dislocated approach to leveraging the partial hydration features. Here @jonathantneal has proposed a very eloquent set of solutions that has been floated somewhat in the past to warm reception but wasn't really been an implementation requirement, however the concerns that have been expressed does warrant a better review over the Given the success of Island architecture and the fundamentals that Astro ships 0kb of JS, to pivot away to where Astro supports the use-case of UI frameworks are Looking at the Proposals, I personally am In favour of proposal 3, which takes the previous 2 proposals and introduces the "client" directive into the assertion object. This I feel is the piece of the jigsaw that has been missing. the following statement helps bring a peaceful, bloodless end to the use-cases 1 through to 4: ---
import Accordion from '../components/Accordion.js' assert { type: 'react-component', client: 'visible' }
--- This can be standardised, and set out clearly in terms of documentation and adoption of its behaviour made gradual up until release of I would like to forward a motion for the proposals provided to merit time within the next possible RFC call to further discuss amongst other stakeholders, |
Beta Was this translation helpful? Give feedback.
-
I like this. We talked a little about this offline but to summarize here:
|
Beta Was this translation helpful? Give feedback.
-
Sorry if this is not the right place to ask this or if this muddies the waters... But is it possible to define the client directive for a particular component once, in the entire codebase? I feel like which client directive I need is most closely tied to the behavior/implementation of the component itself, not where it is used. Like, if I have a component that has dynamic logic in it, it's always going to need Context: I'm considering switching a big site with a lot of static blog-like content over from Next to Astro. I want all the components auto-imported into every mdx file, which already seems possible with this package. I also don't like the idea of having to specify Perhaps if you end up going with an import assertion solution, that can be combined with the auto-import package to achieve what I'm after? Am I right in my assessment that what I'm trying to do is also not possible right now with custom client directives? If you don't end up doing this RFC, or it won't work with auto-imports... it's ugly but maybe you could support like |
Beta Was this translation helpful? Give feedback.
-
Problem
It’s hard to predict what a user wants from an import. We tend to put our expectations into variable names or TypeScript extensions, because file extensions are not reliable.
Proposal 1: Allow Import Assertions
Allow import assertions to not throw in JavaScript, anywhere JavaScript is currently processed (JavaScript, TypeScript, Astro). It would be processed as currently defined in the specification.
type
is"json"
, process the file data as an Object from JSON.Proposal 2: Allow Type Assertions
Allow a
type
assertion on any ECMAScriptimport
, which would determine how the loaded file is processed.type
is"use+astro"
, process the file data as an Astro Component.type
is"use+preact"
, process the file data as a Preact Component.type
is"use+react"
, process the file data as a React Component.type
is"use+svelte"
, process the file data as a Svelte Component.type
is"use+vue"
, process the file data as a Vue Component.type
is present and matches none of these, process the file as a JavaScript Module.Question: Should we allow custom types?
Proposal 3: Allow Client Assertions
Allow a
client
assertion on any ECMAScriptimport
, which would determine how the loaded file is processed.type
is"use+astro"
,"use+preact"
,"use+react"
,"use+svelte"
, or"use+vue"
; then,client
isload
, process the component so that it begins client hydration when the page loads.client
isidle
, process the component so that it begins client hydration when the main thread is free.client
isvisible
, process the component so that it begins client hydration when the element enters the viewport.client
isonly
, process the component so that it loads and hydrates when the page loads.client
directive to override a client assertion.Examples without Import Assertions
Proposal 1
Proposal 2
Proposal 3
Prototype / Demo
Beta Was this translation helpful? Give feedback.
All reactions