-
-
Notifications
You must be signed in to change notification settings - Fork 495
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
Paginated layout removes arguments from liquid shortcode #2154
Comments
First argument is always present. Arguments from second are removed randomly. |
Interesting. I can reproduce w/ > 11ty-2154@1.0.0 build /private/tmp/11ty-2154
> eleventy
www/test/index.html: file1 file2 file3
www/test/1/index.html: file1 file2 file3
www/test/2/index.html: file1 file2 file3
www/test/3/index.html: file1 file2 file3
www/test/2/index.html: main1 undefined undefined
www/test/3/index.html: main1 undefined undefined
www/test/index.html: main1 main2 undefined
www/test/1/index.html: main1 main3 undefined
[11ty] Writing www/test/2/index.html from ./src/test.liquid
[11ty] Writing www/test/3/index.html from ./src/test.liquid
[11ty] Writing www/test/index.html from ./src/test.liquid
[11ty] Writing www/test/1/index.html from ./src/test.liquid
[11ty] Wrote 4 files in 0.06 seconds (v1.0.0-canary.49) Pushed sample repo to https://github.com/pdehaan/11ty-2154 console.log(`@11ty/eleventy@${require("@11ty/eleventy/package.json").version}`);
console.log(`liquidjs@${require("liquidjs/package.json").version}`);
// @11ty/eleventy@1.0.0-canary.49
// liquidjs@9.31.0 |
Hey @pdehaan, I don't think it's related to liquidjs but tonight I had time to look into it anyway and find it quite interesting. I added some log to this file: static async parseArguments(lexer, str, scope, engine) {
let argArray = [];
let label = `[${id++}]`;
if (!lexer) {
lexer = moo.compile(Liquid.argumentLexerOptions);
}
console.log(label, "parsing arguments for string", str)
if (typeof str === "string") {
// TODO key=value key2=value
// TODO JSON?
lexer.reset(str);
let arg = lexer.next();
while (arg) {
/*{
type: 'doubleQuoteString',
value: '"test 2"',
text: '"test 2"',
toString: [Function: tokenToString],
offset: 0,
lineBreaks: 0,
line: 1,
col: 1 }*/
if (arg.type.indexOf("ignore:") === -1) {
const item = await engine.evalValue(arg.value, scope);
console.log(label, "got item:", arg.value, "eval:", item)
argArray.push(item);
}
arg = lexer.next();
}
}
console.log(label, "return array", argArray)
return argArray;
} It prints something like:
This shows the array's value is not expected even before passed to liquidjs. I guess it's related to this line reseting the lexer based on string value: eleventy/src/Engines/Liquid.js Line 105 in 1ea3a90
But in JavaScript strings are immutable, which means the three passes of
The reason why it's may be related to LiquidJS version could be something changed to async and now concurrency actually happens. Nevertheless, I guess it can be a bug to reset the lexer based on string values. First time dig into this so maybe I'm wrong. @zachleat please let me know if there's something need my help. |
Awesome, thanks for the 👀 @harttle! ❤️ |
I'm also noticing this behavior in 1.x eleventy builds when using a template that extends another template. eg: If I extend the base layout in
I get the same random missing args issue. |
I just figured out a proper fix for this and #2348 without having to create a new lexer on each call. Instead of using await on each call to evalValue you have to let it consume the current scope and use a I will submit a PR tomorrow but this is the rough code. Thanks @harttle for pointing in the right direction. |
Looks like we have two different conversations going so I’ll post comments on both 😅
|
And a thank you to @harttle too!! This reminded me also to set up an 11ty sponsorship of Liquid.js cc 11ty/11ty-community#78 |
Describe the bug
Paginated layout removes arguments from liquid shortcode.
To Reproduce
Steps to reproduce the behavior:
Shortcode
Template
test.liquid
:Layout
main.liquid
:Expected behavior
All arguments passed to
test
shortcode in both cases: template and layout.Actual behavior
Arguments are randomly removed from shortcode:
Environment:
Additional context
Maybe other versions of Eleventy and other template engines are affected.
The text was updated successfully, but these errors were encountered: