The link on the Image tag is redirecting to an undefined page from the node preview screen

Created on 7 September 2022, about 2 years ago
Updated 12 August 2024, 3 months ago

Problem/Motivation

On the node preview screen, linked images redirect to an undefined page.

As we can see in the attached screenshot, the direct link with "Click here" is working but the link with image tag get redirecting to the node preview undefined page.
/node/preview/86c2fbcf-11e4-4a56-a4c8-93ab8f382baa/undefined

Steps to reproduce

For demonstration, I will be using a custom block set to full html format. The block has nothing to do with the issue, it is just used to quickly place the testing code onto a page.

  1. Add the following code to a custom block, configured to display on node pages:
    <h1>Normal Link</h1>
    <a href="/">Test</a>
    <h1>Image Link</h1>
    <a href="/"><img src="/path/to/an/actual/image.png"></a>
    <h1>Child Element Link</h1>
    <a href="/" style="padding:20px"><span>Test 2</span></a>
    
  2. Edit a node (that is not the home page)
  3. Click preview button
  4. Click the "normal link", when the modal pops up, click "leave". Observe you are correctly redirected.
  5. Use your browser back button to return to preview mode.
  6. Click the "image link", when the modal pops up, click "leave". Observe you are NOT correctly redirected.
  7. Use your browser back button to return to preview mode.
  8. Click the "child element link", specifically the padded area around the text. When the modal pops up, click "leave". Observe you are correctly redirected.
  9. Use your browser back button to return to preview mode.
  10. Click the "child element link", specifically text itself. When the modal pops up, click "leave". Observe you are NOT correctly redirected.

Proposed resolution

The issue is that the click can come from the link element or a child of it. The JS behavior is attached only to the link. When child element is clicked, event.target.href is undefined. Instead refer to event bubbling and switch to event.currentTarget.href which will always refer to the element that the behavior is attached to.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

🐛 Bug report
Status

Fixed

Version

10.4

Component
Node system 

Last updated about 12 hours ago

No maintainer
Created by

🇮🇳India Shifali Baghel Gurgaon

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

Merge Requests

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.71.5 2024