11ty / webc

Single File Web Components
MIT License
1.3k stars 36 forks source link

Create new component manager per page #176

Open CanIGetaPR opened 1 year ago

CanIGetaPR commented 1 year ago

Create new component manager per page so webc:setup blocks get appropriate per-page contexts

Fixes #174

Zearin commented 1 year ago

@zachleat This PR needs approval.

And love.

Loving approval. ❤️👍🏽

agarzola commented 10 months ago

I applied the patch in this PR to my project and confirmed that it solves #174 and 11ty/eleventy-plugin-webc#69.

hasanhaja commented 9 months ago

I can confirm too that this solves my issue.

Applied patch: https://github.com/hasanhaja/site/blob/main/patches/%4011ty%2Bwebc%2B0.11.4.patch My layout: https://github.com/hasanhaja/site/blob/main/src/_includes/layouts/info.webc

It now correctly builds all of my pages with the layout info.webc with the correct data

PersonMeetup commented 8 months ago

Can also verify the patch works! I was having issues rendering collection navigation within a .webc template, due to the stale data issue this PR addresses. Small sample of the template's code follows:

<script webc:setup>
    const previous = this.getPreviousCollectionItem(collections.apod);
    const next = this.getNextCollectionItem(collections.apod);
</script>
<nav>
    <a webc:if="previous" :href="previous.url">&larr; Previous Day</a>
    <a webc:if="next" :href="next.url">Next Day &rarr;</a>
</nav>
<!-- . . . -->
<p @html="this.content"></p>