Skip to content

Frequent component property/attribute data collisions with global data #151

@zachleat

Description

@zachleat

On 11ty-website I have a src/_includes/components/site-card.webc component which uses a date prop:

<div class="sites-site-vert">
	<a :href="url" class="elv-externalexempt" :title="name || false"><span class="metadata" webc:if="date" @text="`(${date.split('-').shift()})`"></span></a>
</div>

which is fine until I have usage where the prop is left off when used (e.g. on docs/getting-started.webc)

<site-card @date="2023-01-01"></site-card><!-- sure, fine -->
<site-card></site-card><!-- not fine -->

This collides with any top level date set in Eleventy’s data cascade.

My proposal is to move internal components (e.g. src/_includes/components/* in my example) and not top level WebC template pages (e.g. *.webc files in the Eleventy input folder) to need to reference global data in this way as $data.date instead.

This will prevent undesirable collisions but may require component code to change (if it previously accessed global data). In this above example the component doesn’t use global data and expects date to not have a value, thus does not require code changes.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions