withastro / roadmap

Ideas, suggestions, and formal RFC proposals for the Astro project.
290 stars 29 forks source link

Custom Client Directives #583

Closed bluwy closed 1 year ago

bluwy commented 1 year ago

Summary

Support custom client: directives added by integrations

Links

bluwy commented 1 year ago

I added a new non-goal, which I thought could be a common misconception later:

Non-goal:

  • Replay interaction on hydrate, e.g. if a client:click directive hydrates on clicking the button, Astro doesn't replay the click event to trigger some reaction after it hydrates. The user has to click the (now hydrated) button again to trigger a reaction.

Making this work ootb would be really tricky and I think it's better to leave the directives to handle this themselves if needed, since they should have a reference to the island element and event.target to do so.

ematipico commented 1 year ago

Should we have a helper function called defineDirective to make the types more ergonomic?

const directive = defineDirective((load, opts, el)) => {})
bluwy commented 1 year ago

I've thought about it before, but then we'd have to export a new entrypoint (astro/directive) and it's more tooling author-facing that I skipped it for now 😬 I guess a similar example is the image service API which could perhaps benefit with this pattern too.

But if we're in favour of it, I won't mind supporting that though.

ematipico commented 1 year ago

I've thought about it before, but then we'd have to export a new entrypoint (astro/directive) and it's more tooling author-facing that I skipped it for now 😬 I guess a similar example is the image service API which could perhaps benefit with this pattern too.

You raise a good point. We can leave my suggestion for now, and think about it later!

Maybe we could merge all these define* functions inside a single astro/define entry point. Just a suggestion

matthewp commented 1 year ago

I'm moving for a call for consensus on this RFC. Custom client directives has been in experimental since 2.5 without incident. No issues have been filed thus far and no feedback on the API. This will be the final comment period (3 days); if there are no objections this will be merged and the feature can move out of experimental in a future release (likely 2.6).

matthewp commented 1 year ago

It's been 3 days, this RFC is merged!