Description
Hi,
Could you please make DeterministicTwigIdCalculator extendable or overridable from the application?
I recently encountered an issue that took me a while to diagnose. I implemented a scrolling feature based on this tutorial.
Everything worked fine in an older version, but after an update, it stopped working. Instead of appending new items to the component, each new "page" replaced the previous content.
After investigating, I discovered that the issue was caused by Morphdom’s implementation and the deterministic ID calculator. It seems that Morphdom builds an element ID map based on all IDs in the DOM tree. Since I didn't provide a custom ID for one of my deeply nested Live Components, the deterministic calculator assigned it the same ID every time (every "page" has contained same set of ids). This caused Morphdom to behave incorrectly. After explicitly providing an ID for that Live Component, everything started working again.
This is roughly how my pagination code looked like.
{% for item in items %}
<div id="my_item_{{ item.id }}" data-live-ignore>
... very complicated dom and nested Twig / Live Components
<twig:AnotherLiveComponent />
... very complicated dom and nested Twig / Live Components
</div>
{% endfor %}
My proposal is to make the service responsible for providing default IDs to components overridable (e.g., by implementing an interface). This would allow me to do something like this:
class IdProvider implements ComponentIdProvider
{
public function getId(): string
{
throw new \RuntimeException('Provide id to Live Component manually!');
}
}
This approach would enforce the manual definition of element IDs instead of relying on the deterministic calculator, which can cause issues with the "infinite scroll hack" solution.