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

Using async compile function in addExtension causes "this.defaultRenderer is not a function" error #2217

Closed
zachleat opened this issue Feb 12, 2022 · 3 comments
Assignees
Labels
bug feature: 🤟 custom template languages eleventyConfig.addExtension API

Comments

@zachleat
Copy link
Member

zachleat commented Feb 12, 2022

Reported by @sjml here: 11ty/11ty-website#1286 (comment)

Broken and working versions:

module.exports = function(eleventyConfig) {
  eleventyConfig.addExtension("md", {
-    compile: async function (inputContent, inputPath) {
+    compile: function (inputContent, inputPath) {
      return async function(data) {
        return this.defaultRenderer(data);
      };
    }
  });
};
@AramZS
Copy link

AramZS commented Feb 15, 2022

Was just about to file this bug, looking forward to resolution! Glad someone else hit it.

@AramZS
Copy link

AramZS commented Feb 15, 2022

Actually, the bug I hit (defaultRenderer not being on this) was with: https://www.11ty.dev/docs/languages/custom/#overriding-an-existing-template-language

I think it needs to be corrected in that documentation as well?

@zachleat zachleat self-assigned this Feb 16, 2022
@zachleat zachleat added this to the Eleventy 1.0.1 milestone Feb 16, 2022
@zachleat
Copy link
Member Author

There were some missing test cases here, specifically with async compile and async render (and using an arrow function for render or compile). I think we want defaultRenderer available in as many of these cases as we can (though it won’t work when both render and compile are arrow functions, because it needs at least one this to bind to).

Those fixes will ship with 1.0.1. Thanks y’all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug feature: 🤟 custom template languages eleventyConfig.addExtension API
Projects
None yet
Development

No branches or pull requests

2 participants