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

JavaScript Globals unavailable in webc:type="js" #100

Closed
darthmall opened this issue Jan 15, 2023 · 3 comments
Closed

JavaScript Globals unavailable in webc:type="js" #100

darthmall opened this issue Jan 15, 2023 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@darthmall
Copy link

With the old render functions I could do something like this:

<script webc:type="render" webc:is="template">
  function() {
    const now = new Date();
    return now.toString();
  }
</script>

But with the new webc:type="js" I get a TypeError stating that Date is not a constructor. (Same is true for URL.)

<script webc:type="js" webc:is="template">
  const now = new Date();
  now.toString();
</script>
darthmall pushed a commit to darthmall/11ty.webc.fun that referenced this issue Jan 15, 2023
I've updated most of the render functions to use webc:type=js instead of render.
The one exception is the link-canonical component because there seems to be a
problem with JavaScript globals in the new render functions. I've opened an
issue: 11ty/webc#100
darthmall pushed a commit to darthmall/11ty.webc.fun that referenced this issue Jan 15, 2023
The footer was missing because I forgot to remove the @html="content" from the
old root.webc template, which is now base.webc.

I also had to revert the copyright component to the old render type because it
uses `new Date()`. See 11ty/webc#100.
@dryan
Copy link

dryan commented Jan 19, 2023

I also see this for JSON.parse

@JosefJezek
Copy link

JosefJezek commented Jan 27, 2023

@zachleat
Copy link
Member

This fix will ship with WebC v0.9.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

4 participants