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
{{ message }}
Repository navigation
ArrayableLink in Statamic >4.32 causes infinite loop due to array augmentation #9105
If you revert your changes in ArrayableLink.php and try commenting out line 869 of vendor/statamic/cms/src/Entries/Collection.php, are you still experiencing the infinite loop issue?
I am not sure I understand why this fails, in my case it seems like it's part of a code that uses json_encode in some entries that I use as part of a collection that defines a "mega menu" like part of the website. I am guessing json_encode causes some kind of infinite loop.
Any ideas?
To be honest, I am not sure why this was changed at the first place, a link should be a link if I wanted to get the entry data I would use an Entry relationship field instead. I heavily use links and augmenting each of them to bring the whole entry seems like quite a huge performance hit. Not really blaming anyone (tone is sometimes hard to read in text) just trying to understand how I should move forward.
Okay, re-opening and we can take a further look. There was a couple other augmentation / infinite loop issues that PR caused so I assumed it would fix this one too but obviously not.
To be honest, I am not sure why this was changed at the first place, a link should be a link if I wanted to get the entry data I would use an Entry relationship field instead. I heavily use links and augmenting each of them to bring the whole entry seems like quite a huge performance hit. Not really blaming anyone (tone is sometimes hard to read in text) just trying to understand how I should move forward.
I think it was added so you can do things like {{ link_field:title }} to get the title of the page you're linking to, whilst not needing a separate Entries field.
There's probably something we can do to avoid the infinite loop.
I am not sure I understand why this fails, in my case it seems like it's part of a code that uses json_encode in some entries that I use as part of a collection that defines a "mega menu" like part of the website. I am guessing json_encode causes some kind of infinite loop.
@afonic What does your template look like? I can't reproduce the bug using the original reproduction steps.
I managed to do some tests for this, it seems to happen only in nested Link fields, for example I have a Replicator field which has a set that has an Entries field and these entries have a Link field that points to another entry.
However I failed to reproduce it in a clean install so I just changed my blueprints around to move past this.
@duncanmcclean Not 100% sure if it's related; but throwing it here in case you guys can dig up something.
After replacing the toAugmentedArray() with toShallowAugmentedArray() the page loads (but very slowly).
As far as I can tell, we can specify fields (performance tip no. 2) that you want to (bulk) augment for the collection. However, once you cast the collection/pages to JSON, it triggers the Pages ->toJson() method here, which causes a full augmentation of the page (without any selected columns).
Adding $page->selectedQueryColumns(array_keys($data)); to the Structure tag @ line 131 massively speeds up the page, as well as only loads all augmented data that I've specified in my select. This logic should probably (?) be placed somewhere else though, I was just experimenting.
I'm having a related issue which I think might have the same root cause, though the pages themselves load just fine. It's the CP that locks up when I try to edit pages that have nested link fields.
Activity
duncanmcclean commentedon Dec 1, 2023
Hey! 👋
If you revert your changes in
ArrayableLink.phpand try commenting out line 869 ofvendor/statamic/cms/src/Entries/Collection.php, are you still experiencing the infinite loop issue?If you are, then this is the same issue as #9012.
duncanmcclean commentedon Dec 11, 2023
We've reverted #8928 in the latest release which I believe was the cause of this issue.
afonic commentedon Jan 10, 2024
@duncanmcclean I have the same issue at exactly 4.32.0 and I found my way here. After upgrading my site times out.
The fix @mkwia suggests works.
I am not sure I understand why this fails, in my case it seems like it's part of a code that uses json_encode in some entries that I use as part of a collection that defines a "mega menu" like part of the website. I am guessing json_encode causes some kind of infinite loop.
Any ideas?
To be honest, I am not sure why this was changed at the first place, a link should be a link if I wanted to get the entry data I would use an Entry relationship field instead. I heavily use links and augmenting each of them to bring the whole entry seems like quite a huge performance hit. Not really blaming anyone (tone is sometimes hard to read in text) just trying to understand how I should move forward.
duncanmcclean commentedon Jan 11, 2024
Okay, re-opening and we can take a further look. There was a couple other augmentation / infinite loop issues that PR caused so I assumed it would fix this one too but obviously not.
I think it was added so you can do things like
{{ link_field:title }}to get the title of the page you're linking to, whilst not needing a separate Entries field.There's probably something we can do to avoid the infinite loop.
duncanmcclean commentedon Jan 11, 2024
@afonic What does your template look like? I can't reproduce the bug using the original reproduction steps.
afonic commentedon Jan 11, 2024
@duncanmcclean it's something like this:
I am trying to filter out items until I find what causes it, in the
menucollection I heavily uselinkfields to entries.duncanmcclean commentedon Jan 11, 2024
Just to confirm, it isn't fixed if you try upgrading to the latest version?
afonic commentedon Jan 11, 2024
Nope, it is fixed after reverting back to v4.31 or just reverting the changes made to
Link.phpI will investigate further during the weekend.
afonic commentedon Mar 1, 2024
I managed to do some tests for this, it seems to happen only in nested
Linkfields, for example I have aReplicatorfield which has a set that has anEntriesfield and these entries have aLinkfield that points to another entry.However I failed to reproduce it in a clean install so I just changed my blueprints around to move past this.
n-va commentedon Apr 15, 2024
We're able to recreate this with links when they're referring to each other.
Ex: Page A links to Page B, and Page B links to Page A, they are also nested inside sections.
The fix mkwia suggested with swapping to a
->shallowAugementedArray()inLink\ArrayableLinkPage A
Page B
github-actions commentedon Jun 15, 2024
jelleroorda commentedon Sep 11, 2024
@duncanmcclean Not 100% sure if it's related; but throwing it here in case you guys can dig up something.
After replacing the toAugmentedArray() with
toShallowAugmentedArray()the page loads (but very slowly).As far as I can tell, we can specify fields (performance tip no. 2) that you want to (bulk) augment for the collection. However, once you cast the collection/pages to JSON, it triggers the Pages
->toJson()method here, which causes a full augmentation of the page (without any selected columns).Adding
$page->selectedQueryColumns(array_keys($data));to the Structure tag @ line 131 massively speeds up the page, as well as only loads all augmented data that I've specified in myselect. This logic should probably (?) be placed somewhere else though, I was just experimenting.theutz commentedon Dec 2, 2024
I'm having a related issue which I think might have the same root cause, though the pages themselves load just fine. It's the CP that locks up when I try to edit pages that have nested link fields.
But if I change
cms/src/Fieldtypes/Link/ArrayableLink.php
Line 17 in 9120080
toShallowAugmentedArray(), everything loads just fine.Strangely, this only seems to happen when working locally on my mac. On the Linode where I'm running it, things work fine.
n-va commentedon Dec 2, 2024
@theutz do you have Laravel Telescope installed? We found this to be the cause of the issue.
theutz commentedon Dec 2, 2024
@n-va Valid question, as I've had such issues related to that before, but no. Not this time.