-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feature Request] - A new enhanceIslands
hook to add plugins and other setup to Islands
#277
Comments
Given my limited knowledge of frameworks other than Vue, I did more research. Adding plugins after the creation of the app instance is specific to Vue. For example, In contrast, most other frameworks (React, Preact, Solid, Svelte) use their own version of Context API and global stores to handle global injections during or within the app's initialization, rather than as a separate step. Vue's Composition API is a better alternative, but the Vue plugin approach, due to its ease of use, is widely adopted by authors distributing component libraries, i18n, vue-router, pinia, etc. This usage is very consistent across Vue's ecosystem and is often out of the user's control when consuming these libraries. With this in mind, it may be more appropriate and beneficial to confine the proposed Additionally, though not directly related to this specific feature request, considering Astro's support and release cadence for various frameworks with component structures that are JSX/TSX or have a minor flavor of JSX (e.g., Svelte, Astro), would it be more beneficial to re-strategize Iles's scope to focus solely on Vue? What are your thoughts? |
I think that makes sense.
Pre-rendering components from any framework is a useful feature. In practice I've only needed it for Docsearch, though. Would be interested to hear if anyone is mixing other frameworks. I'd be ok having additional features such as |
Thanks Max ✌🏾. I will prepare a PR for review coming weekend 🙂! |
I have created a sample with two vuetify islands (screenshots at the bottom), both of them require initializing of the vuetify plugin with Here is my
I tried passing the Also, as I have a hunch there might be a need for a hook to be exposed to achieve this across the packages. @ElMassimo, any tricks up your sleeves? This could be accomodated as part of your vite-5 PR review. Thanks! I will try again with fresh eyes later. |
We might add the import in |
Thanks for the insights, @ElMassimo! 😃 I finally found some time to work on the new I remembered that you're reviewing the Vite-5 update branch, so I decided to push my changes as a commits to my previous PR. This way, you can merge it as part of your current review that you forked. These are the two new commits While you're working on the Vue client hydrator, it would be great to merge @maoberlehner's PR as well: #178. Even though he raised a question about wrapping, his update successfully wraps async setup under a Suspense. I tested it too. Breaking part of an island into a child component just to wrap it in Suspense seems like unnecessary overhead, and it feels natural for users to fetch data on the client side within It would be awesome if you could push a pre-release update (beta) so we can test everything. Let me know if there's anything else I can do to help. Again, Iles is such a simple yet powerful tool, and I’m excited to keep working with it. Thanks again for your innovative work for the community! |
Just pushed docs update for the new |
Expanding one of the ideas from here - #276. I want to run this past the community before submitting a PR. Please share your thoughts.
Is your feature request related to a problem? Please describe.
The current
enhanceApp
only applies to the "outer" shell app that is used during development (for a nice HMR experience) and during build time to statically generate the app (as explained by @ElMassimo here - #213 (comment)). This is useful for certain use cases (like the usage of Vue plugins), such as what's discussed in this i18n support thread - #6. However, this "outer" app won't be available in the built app.Currently, to use Vue plugins inside interactive Islands, the only way is to add the plugin inside the island, as discussed in these threads: #207, #259, #6 (reply in thread), #118 (comment), #213 (comment), #61 (comment). For example:
This method is very inconvenient, especially when using UI component libraries like Vuetify, where multiple Islands on the page require the same plugin setup. In such cases, we would need to add the following code to each Island. Even if moved outside the SFC, it's an overhead to import the same in each Island.
Describe the solution you'd like
This feature request is for a new
enhanceIslands
API that can enhance islands by hooking into the island app's lifecycle:app.use(plugin)
for plugins like Vuetify, Pinia, etc.Provider
to manage global data (i18n, themes, etc.).Unlike
enhanceApp
, which applies to the Vue shell,enhanceIslands
would apply to all supported frameworks (e.g., Svelte, Preact, Solid). Users would need to manage conditional setup based on the framework-specific setup. Open to suggestions here 😄.Here's one idea: we could use a simple
iles
attribute as a convention on the hydrated island definition, pass it to the app object, and use it withinenhanceIslands
to conditionally apply the required setup.The API could look like this:
Describe alternatives you've considered
Astro had a similar API proposal (https://github.com/withastro/roadmap/blob/app-setup/proposals/0000-app-setup.md) to introduce an
appEntrypoint
for all supported frameworks as part of this PR: withastro/roadmap#326.Later, Astro, in their community call stream on 4/10/22, decided to drop this idea and introduce
appEntryPoint
only for Vue via their Vue integration community call stream on 19/10/22 with this PR: withastro/astro#5075. In this, the user creates a_app.ts
file and passes it as theappEntryPoint
in their Astro Vue integration, which becomes a Vite virtual module, applying the "setup" (likevue.use
plugins) for all Vue Islands.Another related thread - withastro/roadmap#810
We already have the
app.ts
entry, and the newenhanceIslands
can be framework-agnostic, which I believe will be simpler from a usage perspective. Moving to a "framework-specific" module would create a new "layer" in the workflow, which is what Astro follows (via their integrations API) which does have its advantages.Additional context
This new
enhanceIslands
API added to the Iles core will be consumed by framework-specificcreateFrameworkIsland
(e.g.,createVueIsland
) modules. For example, in: https://github.com/ElMassimo/iles/blob/main/packages/hydration/vue.tsThe text was updated successfully, but these errors were encountered: