Problem/Motivation
Steps to reproduce:
- embed a node
- configure it to be displayed as Teaser
- add caption and/or alignment
- check display of embedded node in some other place (/node for example)
- Expected result: no embed-specific things can be seen
- Actual result: data-align and/or data-caption can be found on tag that was previously embedded
Another sequence of steps that is most likely caused by the same issue:
- Fresh install
- Enable Entity embed
- Configure CKEditor to use Node embed button
- create node that will be embedded
- create host node
- Embed child node, set alignment to none
- Save
- Embedded node is displayed as part of the host node
- Edit host node
- Edit embed settings, set alignment to left
- Embedded node is aligned in WYSIWYG
- Save
- Expected result: Embedded node is now aligned as configured
- Actual result: Embedded node is not aligned
This happens because we add data- tags to the render array that belong to the embedded entity (which gets cached).
Proposed resolution
Add a wrapper around embedded entity and move embed-specific attributes to it.
Comment | File | Size | Author |
---|---|---|---|
#26 | 2712111-24-fixed.patch | 11.46 KB | paranojik |
| |||
#24 | interdiff-22-24.txt | 3.9 KB | paranojik |
#22 | 2712111_22.patch | 8.95 KB | slashrsm |
| |||
#22 | interdiff.txt | 2.92 KB | slashrsm |
#17 | interdiff.txt | 2.12 KB | slashrsm |
Comments
Comment #2
paranojik CreditAttribution: paranojik as a volunteer commentedCross posting from github:
Problem was that the data attributes were added to the embedded entity itself. This caused the same data attributes to appear everywhere the same view mode was used/displayed on the site. That also meant that the cached version was not invalidated until the embedded entity's cache was cleared.
To prevent all mentioned problems we wrap the embedded entity and append the data attributes to the wrapper element.
Pull request: https://github.com/drupal-media/entity_embed/pull/220
Comment #3
slashrsm CreditAttribution: slashrsm as a volunteer commentedUpdate attribute section.
Comment #4
Wim LeersThe filter that renders embedded entities must associate the necessary cacheability metadata. It sounds like that's not happening.
This is therefore basically a duplicate of #2593379: Analyze/improve/fix handling of bubbleable metadata in entity_embed. This only covers one of the many potential side-effects/consequences. The lack of test coverage for this is what's the real problem:
EntityEmbedFilterTest
only tests if something works at all, not if it is updated when necessary. We should at least test:Comment #5
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedI don't agree with #4. This is a different issue than #2593379: Analyze/improve/fix handling of bubbleable metadata in entity_embed. See my comment on GH: https://github.com/drupal-media/entity_embed/pull/220#issuecomment-21709...
Also updating the title as it is misleading.
Comment #6
Wim LeersEven if they're not the exact same problem (which means this issue summary doesn't do a good enough job explaining the problem), they're at least strongly related.
I stand by my statement that the real problem is the lack of test coverage for cache-related aspects of the Entity Embed filter. If we'd have that, then there would also be far less potential for confusion.
Comment #7
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedCompletely agree on that. It is very likely that I'll have some time to look into both issues next week (incl. tests). Thank you for the feedback.
Comment #8
Wim LeersCool :) I will be able to review this patch. If you get stuck, I should be able to find time to help with the patch itself, but that may take longer. So, you rolling the patch and me unblocking you on reviews would be perfect IMO.
Comment #9
paranojik CreditAttribution: paranojik as a volunteer commentedI'm attaching the test scenario that should indicate what the main problem is.
Comment #12
paranojik CreditAttribution: paranojik as a volunteer commentedAdding the wrapper broke EntityEmbedHooksTest tests.
Comment #13
Dave ReidCan we check if the caption & alignment filter in core removes the data attributes or keeps them on image elements?
Comment #14
Dave ReidComment #15
slashrsm CreditAttribution: slashrsm at MD Systems GmbH commentedThey do, but this happens after the rendered entity was cached.
Comment #16
Dave ReidI'm guessing we lack test coverage for this, since I would wager this is a regression.
Comment #17
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commentedIt is actually not a regression. Since we're adding additional wrapper on the embedded entity we don't need this any more. Adding test that proves this (and is beneficial in any case as we currently have no test coverage for this).
I don't like the fact that we need to add a wrapper, but it seems that this is the only way to fix this bug and still keep all the embed specific attributes.
Unrelated: It seems that EntityEmbedFilterTest could be converted to a kernel test. Follow-up?
Comment #18
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commentedAlso, while working on this issue @paranojik and myself noticed that #2528314: template_preprocess_node() does not add cacheability metadata also applies to Entity embed. It is not related to this bug, but definitely something we should watch and help to fix if possible.
Comment #19
Dave ReidI guess my next question, is with the wrapping element, how would #2640398: Allow <drupal-entity> elements to be inline CKEditor Widgets be possible with the wrapping div forced back on now? Eventually supporting inline displays of file entities was on the list, and I would like to make sure we're not backing ourselves into a corner again.
Comment #20
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commentedI dislike the fact that we're adding a wrapper too. Not only for the reasons @Dave Reid brought up, but also from the clean markup standpoint. Unfortunately I don't see any other solution for this problem for now.
Could we use some other html element that would allow us to work with inline elements?
Comment #21
Dave ReidAfter reading more about cache contexts and render cacheability, I think the wrapper might be the only way.
Comment #22
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commentedI created a custom container template which should allow for overrides if non-default wrapper element is needed. Decided for to be the default. Any suggestions about that are welcome, but it seemed better than
Comment #23
paranojik CreditAttribution: paranojik as a volunteer commentedSeems OK to me. After re-reading the W3C spec (https://www.w3.org/TR/html5/sections.html#the-article-element) looks like
<article>
is an appropriate choice for the wrapper element....but shouldn't we add some tests for the wrapper too?
Comment #24
paranojik CreditAttribution: paranojik as a volunteer commentedUpdated tests with asserts for the new wrapper element....
Comment #26
paranojik CreditAttribution: paranojik as a volunteer commented....argh. Screwed up creating the patch :) Uploading a new one. Interdiff still holds.
Comment #27
paranojik CreditAttribution: paranojik as a volunteer commentedComment #28
Dave Reid<article>
is already used for nodes, so now we would have two consecutive/nested article tags, which seems like it's heading in a strange direction?Comment #29
paranojik CreditAttribution: paranojik as a volunteer commentedIt is a bit strange, I agree. On the other hand the spec states
and from this perspective it might be OK.
IMHO either
<article>
or<span>
should be used.Comment #30
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commentedI think that
<article>
should be semantically OK. I thought it would be better than<div>
, which has no meaning at all.Comment #31
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commentedComment #33
slashrsm CreditAttribution: slashrsm at MD Systems GmbH for Acquia commentedCommitted. Thanks!