Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,16 +286,17 @@ document.addEventListener("turbolinks:load", function(e) {
this.dataset.origHeight = this.clientHeight;
this.style.maxHeight = '' + limit + 'px';
this.classList.add('tess-expandable-closed');
var btn = $('<a href="#" class="tess-expandable-btn">Show more</a>');
const btn = $('<a href="#" class="tess-expandable-btn">Show more</a>');
btn[0].expandableTarget = this;
btn.insertAfter($(this));
}
});

$(document).on('click', '.tess-expandable-btn', function (event) {
event.preventDefault();
var div = this.parentElement.querySelector('.tess-expandable');
var maxHeight = parseInt(div.dataset.origHeight) + 80;
var limit = parseInt(div.dataset.heightLimit || "300");
const div = this.expandableTarget;

Copilot AI Feb 12, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Binding the expandable div via a custom JS property (btn[0].expandableTarget) is not preserved across Turbolinks snapshot caching (custom/expando properties are lost when the DOM is serialized/cloned). Because the code also short-circuits when data-orig-height is present ("Prevent double bind"), a cached page restored via back/forward navigation can leave .tess-expandable-btn in the DOM without expandableTarget, causing the click handler to throw when it reads div.dataset.... Prefer persisting the association in the DOM (e.g., assign an id to the .tess-expandable and store it on the button via aria-controls/data-target, or re-bind expandableTarget to any existing adjacent button even when data-orig-height is already set).

Suggested change
const div = this.expandableTarget;
// Prefer the explicitly bound target, but fall back to the preceding
// .tess-expandable element. This avoids relying solely on expando
// properties, which are lost across Turbolinks snapshot caching.
var div = this.expandableTarget || $(this).prev('.tess-expandable')[0];
if (!div) {
// No associated expandable div found; do nothing to avoid errors.
return false;
}

Copilot uses AI. Check for mistakes.
const maxHeight = parseInt(div.dataset.origHeight) + 80;
const limit = parseInt(div.dataset.heightLimit || "300");

if (div.classList.contains('tess-expandable-closed')) {
div.classList.add('tess-expandable-open');
Expand Down
Loading