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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webc:type="js" throws on missing props #85

Closed
oliverjam opened this issue Dec 1, 2022 · 2 comments
Closed

webc:type="js" throws on missing props #85

oliverjam opened this issue Dec 1, 2022 · 2 comments
Assignees
Labels
bug Something isn't working
Milestone

Comments

@oliverjam
Copy link

The webc:type="js" examples in the docs don't work correctly atm, as the "js" type behaves differently to the old "render" type. If a prop is not passed to the component it throws when you try to access it. This means you can't even check if the prop exists 😅

<script webc:type="js">
  if (alt) {
    `<img src="${src}" alt="${alt}">`;
  } else {
    `<a href="${src}">Your image didn’t have an alt so you get this link instead.</a>`;
  }
</script>
[11ty] ReferenceError: alt is not defined
[11ty]     at evalmachine.<anonymous>:2:3
[11ty]     at Script.runInContext (node:vm:141:12)

Doing the equivalent with this.alt in a webc:type="render" component works fine.

@zachleat zachleat added the bug Something isn't working label Dec 1, 2022
@zachleat
Copy link
Member

zachleat commented Dec 1, 2022

Reproduced!

@zachleat zachleat self-assigned this Dec 1, 2022
@zachleat zachleat added this to the WebC v0.8.0 milestone Dec 2, 2022
@zachleat
Copy link
Member

zachleat commented Dec 2, 2022

Fixed, will ship with WebC 0.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants