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

If a layout defines an array front matter variable, and a page that uses the layout overrides the array in eleventyComputed, the override applies to all pages that use the layout #3728

Open
AleksandrHovhannisyan opened this issue Mar 24, 2025 · 0 comments

Comments

@AleksandrHovhannisyan
Copy link
Contributor

Operating system

Windows 10, WSL 2 (Ubuntu 20)

Eleventy

Reproducible on both 3.0.0 and 3.0.1-alpha.5

Describe the bug

Let's say you have a layout file that defines an array front matter variable that's common to all pages that use this layout. I'll create two arrays, one that will be overridden in eleventyComputed and one that won't:

src/_layouts/base.liquid

---
nonComputedArray: ["base"]
computedArray: ["base"]
---
<!DOCTYPE html>
<html>
	<head></head>
	<body>{{ content }}</body>
</html>

And then suppose you have two pages that use this layout. One is a collection item (doesn't have to be a collection item):

src/_collection/item.md (a collection item)

---
layout: base
tags: ['collection']
nonComputedArray: ['override']
eleventyComputed:
    computedArray: ['override']
---

<!-- output: ['override'] -->
{{ computedArray | log }}

<!-- output: ['base', 'override'] -->
{{ nonComputedArray | log }}

And another is just a plain index page that also uses the same layout:

index.liquid

---
layout: base
---

<!-- Output: ['override']. This is bad/unexpected. -->
{{ computedArray | log }}

<!-- Output: ['base', 'override']. This is expected. -->
{{ nonComputedArray | log }}

Let me explain what happened here: Somehow, if you set computedArray: ['override'] in eleventyComputed in src/_collection/item.md's front matter, it mutates the array globally in the layout context so that a completely unrelated page (index.liquid) that uses the same layout now also sees ['override'] when instead it should see ['base'] (since it didn't make any changes of its own, and thus I'd expect the layout's default values to have been inherited).

Reproduction steps

  1. Clone this repo: https://github.com/AleksandrHovhannisyan/11ty-sandbox
  2. Check out this branch: eleventyComputed-array-merging
  3. Run npm install to install dependencies.
  4. Run npm serve to start the local dev server.
  5. Observe the output logged to the terminal console.
  6. You can also edit the collection item index.md to log the same values.

Expected behavior

Arrays should be recursively merged. setDataDeepMerge makes no difference (enabled by default anyway).

Also, I would not expect the override from src/_collection/item.md to have affected the base index.html file.

Reproduction URL

No response

Screenshots

No response

@AleksandrHovhannisyan AleksandrHovhannisyan changed the title Using eleventyComputed with an array results in global layout data being overridden for all pages Using eleventyComputed with an array results in global layout data being overridden for all pages that use that layout Mar 24, 2025
AleksandrHovhannisyan added a commit to AleksandrHovhannisyan/aleksandrhovhannisyan.com that referenced this issue Mar 24, 2025
@AleksandrHovhannisyan AleksandrHovhannisyan changed the title Using eleventyComputed with an array results in global layout data being overridden for all pages that use that layout If a layout defines an array front matter variable, and a page that uses the layout overrides the array in eleventyComputed, the override applies to all pages that use the layout Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant