Replies: 2 comments 4 replies
-
Sounds good! I'm +1 generally and don't have any strong opinions on implementation in the compiler. Will leave that to @natemoo-re and others. I'm not sure I follow the need for If there's no push-back, I'd love for this RFC to state that all Astro directives must be static in the template. I think that's easier to document across all directives vs. only some, and I think more often than not a directive is meant as a signal/instruction to the compiler that would be hidden if applied dynamically. |
Beta Was this translation helpful? Give feedback.
-
@FredKSchott I believe that there is a viable way to achieve the same result without the directive attribute itself being dynamic; specifically ---
import MyComponent from '../components/Mine.jsx';
let attrs = {
'client:load': Math.random() > 0.5
}
---
{attrs['client:load']
? <MyComponent client:load />
: <MyComponent />
} (And I think this would remain available under this proposal.) This seems like it would be sufficient unless I am failing to imagine some case where multiple dynamically selected directives lead to a combinatorial explosion of cases. @matthewp If I understand the proposal correctly, this code would end up bundling |
Beta Was this translation helpful? Give feedback.
-
In order to improve the build we want to prevent scanning the generated HTML to find JavaScript usage in order to bundle.
One aspect of doing that is knowing which client directives to build. If we can assume that they are static within the .astro file, we can know which directives to build. For example:
Using this information we know that both
/src/components/Mine.jsx
andastro/client/load.js
need to be built. If we assume that this attribute cannot be added dynamically.For example:
We would not know that this component is using the
client:load
directive.Rough proposal
$$metadata
(this export already exists to collect hydrated components).client:statically-added
Alternative
One possibly workaround that would enable having dynamic usage of client directives would be if we always bundled the client directives. This would mean that:
Would all be built to the
dist/
folder and at runtime the right one would get used.Beta Was this translation helpful? Give feedback.
All reactions