-
-
Notifications
You must be signed in to change notification settings - Fork 504
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 11ty.js templates support returning a buffer (sync render
)
#3629
Comments
I can reproduce (although not on Stackblitz because of how they build (using musl)).
eleventy/src/Engines/JavaScript.js Line 76 in b662229
is the default module you return. Therefore eleventy/src/Engines/JavaScript.js Line 227 in b662229
is called which produces a binary file (I have logged the output). The binary appears fine although my image viewer reports it as broken. So I digged a little deeper: xxd _site/noise.png > noise.hex # Using async render
xxd _site/noise_broken.png > noise_broken.hex # Using sync render
diff --suppress-common-lines -y noise.hex noise_broken.hex
stat -c %s _site/noise.png
stat -c %s _site/noise_broken.png The diff showed a longer file on the right side (the broken version) Logging |
Problem in this code: eleventy/src/Engines/JavaScript.js Lines 34 to 40 in b662229
eleventy/src/TemplateContent.js Line 586 in b662229
When function returns a promise, condition With sync render inside |
I assume, it's designed for raw Buffer values. Therefore I think the first step would be to add tests to https://github.com/11ty/eleventy/tree/b6622297b72e5b1d7d7d01f2c3008aacd39ec517/test/Util so we catch the current behaviour (and a failing test for what you intend to do). A „quick” solution could be extending the signature of the normalize function to consider |
I see similar discussion here - #2352. I think buffer should not be special handled. If user use buffer, he knows how to work with one. |
Hm, introduced back in v0.7.0: 9072cbc That was the release that introduced this Template Engine: https://github.com/11ty/eleventy/releases/tag/v0.7.0 I agree with you:
|
Hm! I’m okay adding this but if it’s not a 3.0 regression it will need to be moved to 4.0 as a breaking change |
In the mean time I’d welcome a PR that adds a configuration API opt-in to unlock this behavior in 3.0 |
render
)
Hi Zach, yeah, it pretty much sounded like a breaking change to me. But then, we have one thing to look forward to in Eleventy v4 now 😇 |
@monochromer Do you have thoughts on how that API might look like? |
Maybe something like that: // template.11ty.js
export default {
// think about naming
eleventyJavaScriptTemplateOptions: {
blob: 'bypass' /* or `string` or function to transform buffer */
/* or */
postProcessRenderedResult: (result) => {}
},
data: {},
render(data) {
const buffer = getBufferSomehow();
return buffer;
}
} |
I have issue with buffers returned from js template:
When i use async render function, it works fine. But with sync render i got broken image.
Code - https://stackblitz.com/edit/stackblitz-starters-jojfy7jh
The text was updated successfully, but these errors were encountered: