Having the same type of entity on one page with comments enabled breaks the HTML ID uniqueness of the wrapper

Created on 9 April 2021, about 3 years ago
Updated 26 July 2023, 11 months ago

Problem/Motivation

When you display the same type of entity on the same page multiple times with comments enabled (via Views), the wrapper ID stop being unique. Since this is passed through Html::getUniqueId this is not a problem on the first page load, but becomes an issue when one entity has a change in its comments and needs to be rerendered. Again this work fine for the normal AJAX reload, but when reloading the page only the changed entity will be rerendered but outside the context of the full page, so Html::getUniqueId will not do anything and the ID will not be unique, and worse the data-wrapper-html-id will point to the wrong entity, so any updates done will be shown on the wrong entity.

Steps to reproduce

  • Build a View that displays your entities that have a comment field using ajax_comments, with the full entities being rendered (including the comment form)
  • Add 2 entities of the same bundle so they are shown in the View
  • Go to the page that shows the View
  • Add comments to the SECOND entity
  • Reload the page
  • Add a comment to the SECOND entity again, the AJAX feedback will be shown on the first entity

Proposed resolution

Make the wrapper ID more specific and don't depend on Html::getUniqueId by adding the ID of the commented entity to the ID.

Remaining tasks

Patch and review

πŸ› Bug report
Status

RTBC

Version

1.0

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands Lendude Amsterdam

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024