Refresh alert on path rewrite

Created on 11 November 2022, about 2 years ago
Updated 16 May 2023, over 1 year ago

Problem/Motivation

An alert will honor a new path once it refreshes (e.g. if restricted to /shop/123 and the url gets rewritten to /shop/345), but not directly after the path change. It would be good to refresh the alert on the event of a path change even if there is no page reload (client side routers).

Steps to reproduce

1. Add an alert and restrict it to a specific url
2. navigate to the url and see the alert
3. navigate away from the url by rewriting browser history via JS
4. see that the alert will only disappear once it refreshes based on the refresh settings

Proposed resolution

Listen to history manipulation events and refresh the alert on every change.

Feature request
Status

Fixed

Version

2.0

Component

Code

Created by

🇩🇪Germany stefanweber Frankfurt/Main

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.

  • 🇩🇪Germany dreizwo

    Checking this issue

  • 🇩🇪Germany dreizwo

    To have a simply reproducer - do following:

    * Do a fresh install and enbale sitewide_alter as recommended.
    * Enable automatic refresh
    * Create a Node that should show an alert (add sitewide_alter and restrict to this node )
    * add this snippet (f.x. with custom block ) somewhere on this site to simulate pushstate and history manipulation:

    <div>
    <h2> Client Side Navigation </h2>
    <button onClick="push('/node/1')">Show alert</button>
    <button onClick="push('/node/2')">Don't show alert - Push</button>
    <button onClick="replace('/something/other')">Don't show alert - Replace</button>
    <button onClick="history.back()">Back</button>
    <button onClick="history.forward()">Forward</button>
    </div> 
    
    <script>
    function push(url){
       history.pushState({"page": url}, '', url);
    }
    function replace(url){
       history.replaceState({"page": url}, '', url);
    }
    

    * render node/1

    If the history is changed by any third party lib, the rendered alert is not dismissed or re-initialized until the automatic refresh is executed.

    Unfourtunatly - if the history is changed by pushstate events - you will not receive a onpopstate event we could listen for. Therefore this patch contains a proxy based hook to dispatch a custom event.

    After applying patch the alert is immediatly rendered/dismissed.

  • Status changed to Needs review almost 2 years ago
  • 🇮🇳India Jasjeet Kaur Brar

    Hi @dreizwo I followed all the steps mentioned in #3 but unable to reproduce it.

  • Status changed to RTBC over 1 year ago
  • 🇪🇸Spain alexortega_98 Seville

    I could reproduce it,before the patch, it took around 15 seconds to load the alert, but after it, the alert shows right away without problems.

  • 🇺🇸United States chrissnyder Maryland
  • Status changed to Fixed over 1 year ago
  • 🇺🇸United States chrissnyder Maryland
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024