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

Inconsistent {% continue %} Behavior in Snippets Between Shopify Liquid and LiquidJS #779

Closed
mattvague opened this issue Dec 9, 2024 · 2 comments · Fixed by MinistryPlatform-Community/MPCustomWidgets#9

Comments

@mattvague
Copy link
Contributor

mattvague commented Dec 9, 2024

The behavior of {% continue %} inside snippets seems to differ between Shopify Liquid and LiquidJS. In Shopify Liquid, {% continue %} effectively acts as an "early return" from the snippet, preventing any further code in the snippet from rendering. However, in LiquidJS, {% continue %} behaves as it would inside a loop, causing the loop in the parent context to skip to the next iteration.

Steps to Reproduce:

  1. Create a Liquid snippet (example-snippet.liquid):
{% continue %}
<p>This part of the snippet should be skipped</p>
  1. Use the snippet in a layout/section with a parent loop in LiquidJS:
{% for i in (1..3) %}
  <p>Loop iteration: {{ i }}</p>
  {% render 'example-snippet' %}
  <p>This code will be skipped in LiquidJS, but not Shopify Liquid</p>
{% endfor %}

Expected Behaviour (based on Shopify Liquid):

<p>Loop iteration: 1</p>
<p>This code will be skipped in LiquidJS, but not Shopify Liquid</p>
<p>Loop iteration: 2</p>
<p>This code will be skipped in LiquidJS, but not Shopify Liquid</p>
<p>Loop iteration: 3</p>
<p>This code will be skipped in LiquidJS, but not Shopify Liquid</p>

What I actually get with LiquidJS is this:

<p>Loop iteration: 1</p>
<p>Loop iteration: 2</p>
<p>Loop iteration: 3</p>

I know that this may seem like a bit of an edge case, but I've seen devs using {% continue %} in Snippets as an early return fairly commonly so should probably be fixed

@harttle harttle added the bug label Dec 9, 2024
@harttle
Copy link
Owner

harttle commented Dec 22, 2024

Seems include and render behaves differently. include in liquidjs is correct skipping the rest of for body, but continue in snippets called by render should only skip its content.

github-actions bot pushed a commit that referenced this issue Dec 22, 2024
## [10.19.1](v10.19.0...v10.19.1) (2024-12-22)

### Bug Fixes

* add sideEffects=false to package.json ([734eb52](734eb52))
* inconsistent continue behaviour, fixes [#779](#779) ([e3ef574](e3ef574))
* memoryLimit doesn't work in for tag, [#776](#776) ([2af297f](2af297f))
Copy link

🎉 This issue has been resolved in version 10.19.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants