You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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:
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).
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
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
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
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)
And another is just a plain index page that also uses the same layout:
index.liquid
Let me explain what happened here: Somehow, if you set
computedArray: ['override']
ineleventyComputed
insrc/_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
eleventyComputed-array-merging
npm install
to install dependencies.npm serve
to start the local dev server.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 baseindex.html
file.Reproduction URL
No response
Screenshots
No response
The text was updated successfully, but these errors were encountered: