Problem/Motivation

Steps to reproduce

1. enable cookies_twitter_media, media_entity_twitter
2. Add #editCookieSettings menu link to footer for example
3. Create twitter media type - on Manage display set Tweet URL field formatter to Twitter embed
4. add twitter media field to a node type. Make it have unlimited amount of values - on Manage display set media's field formatter to Rendered entity
5. create a node with 3 twitter media
6. open node and click to Enable twitter cookies

Expected behavior:
Each and every twitter post should display as it was saved. See attached screenshot expected.png

Actual behavior:
The very first twitter post loads 3 times. See attached screenshot actual.png But if you refresh the page now, then the correct posts are showing suddenly. I'm not sure which script causes the problem. Could be this module's or just the Twitter's JS.

The same thing happens if we embed these media to the text with CKEditor.

I'm putting the status to critical because for a news website that embeds social media posts for community news and reactions this issue means loss of content and the visitors are not seeing properly what the editors created.

Proposed resolution

Remaining tasks

User interface changes

API changes

Data model changes

CommentFileSizeAuthor
expected.png1.56 MBkaszarobert
actual.png1.49 MBkaszarobert

Issue fork cookies-3312226

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

kaszarobert created an issue. See original summary.

lexsoft’s picture

+1 I can confirm that this also happens to me with multiple Vimeo and Youtube videos on the same page. It duplicates the first iframe across all iframes.

Drupal Version
9.4.8

Web Server
nginx/1.22.0
 
PHP
Version
8.0.21 (more information)
Anybody’s picture

Hi all,

I wasn't able to reproduce this yet. It sounds as your live sites are affected? If yes, would you mind to share an example URL to test this?
Hopefully we can fix this ASAP then.

I guess there's something wrong in the JS implementation. Which exact Cookies module version are you using?

Anybody’s picture

Assigned: Unassigned » Grevil

Best would be to have a JavaScript tests reproducing what's visible, for example using three YouTube Videos, but I guess that test will be quite complicated to set up @Grevil?

Furthermore in a perfect world, we'd need the test for every submodule to ensure they all work.

For your manual tests, youtube might be the easiest integration with Drupal Core Media Remote Video.

kaszarobert’s picture

Hi!

I'm currently using latest Drupal (9.4.8) and latest COOKiES (1.1.0). I installed a site at simplytest to demonstrate it with Youtube videos as it was said in #2 it affects those media types too: https://master-hrhrjx947xhngsmrydpodoqu8kmjv49b.tugboatqa.com/node/1

Please load the page, accept video cookies and notice that the same Youtube video is embedded 3 times. Now hit refresh the page, and now suddenly 3 different video shows (this should be the correct one because if you login as admin, you can see that I put 3 different video media to this node).

On a production page we used a quick fix by reloading the page when the consent is changed. But I'd like to know if there are more appropriate solutions to this problem.

Grevil’s picture

Can confirm, that this issue is reproducible, we are working on a fix ASAP!

Anybody’s picture

Status: Active » Needs review

@Grevil my guess is, that the var in the for loop is only set at the first run and never overwritten then. Seem to be a special case in JavaScript loops that we should be aware of?

Still not sure, as it looks crazy, but I think this might be the faulty line:
var $element = $(element);

For our own interest, please also check if a let instead of var would fix it.
Then we should use that in the Drupal 10 Cookies release with Vue...

But first, please try, if my assumption is right.
And if yes, this needs to be fixed in every submodule using a similar implementation.

Anybody’s picture

Status: Needs review » Needs work

Confirming we can reproduce the issue and we're quite confident we found the reason. Working on it with @Grevil!

Anybody’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests

@Grevil I think I finally found it:
Seems this was the key issue. We were looking for the wrapper globally, instead of relative:

Wrong:
var $wrapper = $(document).find('.' + serviceBaseWrapperStr);

Correct:
var $wrapper = $(this).parent('.' + serviceBaseWrapperStr);

Still the other fixes were also relevant, I think.

I guess it's worth to have JS tests to ensure
a) only the selected service type is unlocked
b) the result is exactly the same after unlocking as it's after a page reload

Please first test manually now, that my fix solves the issue and doesn't introduce new issues, hopefully. That's what the tests will also be good for.

@kaszarobert and @lexsoft please check, if the MR fixes the issue for you or if you find other issues with this fix now. Quite complicated part here... -.-

Anybody’s picture

FYI: I added just this fix as simple experiment in !56 to see if that would also work.

Anybody’s picture

MR!56 also fixes the issue and is less disruptive.

For that reason I'm going to commit this now as quick-fix. @Grevil afterwards I think we should add tests here and if we find further issues, let's look into MR!55 again, otherwise let's close that far more complicated one. Seems my assumptions regarding the variables here were not matching (in this specific case - the general logic hint is still important for (event) callbacks!)

Anybody’s picture

Status: Needs review » Reviewed & tested by the community
Anybody’s picture

Status: Reviewed & tested by the community » Needs work

Merged MR!56 as simple fix to at least remove this clear logical mistake and marked the complex MR!55 as Draft.
Let's proceed with tests and feedback here now!

  • Anybody committed e8c92cd on 1.1.x
    Issue #3312226 by Anybody, Grevil: Wrong embedded content could be...
Grevil’s picture

Status: Needs work » Fixed

Let's create another issue for creating the tests, so this issue won't get cluttered.

Anybody’s picture

Assigned: Grevil » Unassigned

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.