Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for detecting islands in pug templates #83

Open
luminarious opened this issue Feb 3, 2022 · 4 comments
Open

Add support for detecting islands in pug templates #83

luminarious opened this issue Feb 3, 2022 · 4 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@luminarious
Copy link

Description 馃摉

client:* directives cannot be used with Pug templating language.

Reproduction 馃悶

https://stackblitz.com/edit/iles-dy6fcn?file=src/pages/index.vue
None of the GrowButtons are recognized as islands.

@luminarious
Copy link
Author

Stackblitz runs dev mode by default, have to manually stop and run npm run build && npm run preview

@ElMassimo
Copy link
Owner

ElMassimo commented Feb 4, 2022

Hi again Hardi!

Currently, hydration directives are detected by traversing the template nodes obtained using parse from @vue/compiler-sfc, and then checking whether a node has a client: property.

For Pug templates, @vue/compiler-sfc will parse the template as text (instead of html nodes), which means the current algorithm does not have the necessary data to work with.


I'm open to adding support for pug, as long as it doesn't affect performance for other use cases.

It's likely that it will require using the pug engine to parse the template content and obtain an AST or some kind of tree, which allows traversing the nodes to detect hydration directives, to then wrap those nodes inside an Island.

Let me know if you are interested in exploring this, contributions are welcome!

@ElMassimo ElMassimo added enhancement New feature or request help wanted Extra attention is needed labels Feb 4, 2022
@ElMassimo ElMassimo changed the title client:* directives cannot be used with Pug templating language. Add support for detecting islands in pug templates Feb 4, 2022
@luminarious
Copy link
Author

I wish I could be of any help there, but parsing and compilation are so far outside my comfort zone 馃槄

Would it be possible to add the entire Island component manually, instead of using the attribute?

@ElMassimo
Copy link
Owner

parsing and compilation are so far outside my comfort zone 馃槄

It's ok, just checking. I might be able to take a look over the next couple of weeks.

Would it be possible to add the entire Island component manually, instead of using the attribute?

Possible, yes, but very cumbersome (to a point where using an html template might end up being more convenient, ha)


In the meantime, a workaround if you want to keep using pug, is to create a dummy component with a normal template, and apply the hydration tags passing any additional props:

// src/components/LazyGrowButton.vue
<template>
  <GrowButton client:load v-bind="$attrs"/>
</template>

You can then use LazyGrowButton in pug templates without issues, and it will be hydrated as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants