-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[🐞] Weird location.hash / window.history behaviour #6184
Comments
Interesting issue, when upgrading to SPA, QwikCity will hijack all same-page anchor tags because Firefox destroys history state when clicking hash anchors. It also only ever fires a Looks like this will only scroll to an element if it's already visible, it won't expand the details element. The reason Link works on stackblitz is because stackblitz breaks the QwikCity router/useNavigate location and Link thinks it's navigating to a different website so it doesn't scroll, it uses The only real solution to this issue I think is to use |
@jordanw66 thanks a lot. I was pretty sure stackblitz is reloading, but wasn't that smart to check network tab 😶🌫️ we will try with Can you point me in the right direction in qwik? Not sure if we could check if the element is visible and if not, use location.href in qwik instead? |
@jordanw66 it seems that anchor tag works before the first Form submission and it does scroll to the element before it is visible (opens the details element) - it's only Link that will not open the details element (and works if it's already open). However, we tried setting
both in the onClick$ of the In the meantime we'll do a workaround with a custom context. |
So what's going on specifically, so there's no confusion, is that Regular Before submitting the form, When you submit the form, that forces an SPA reload, which upgrades the current page/history entry to SPA, as a result this now hijacks the same-page (hash/fragment) At this point The reason I think the issue you're having with Lastly, I'd say real quick be careful with If the page is already on the fragment, simply calling Two solutions to this problem:
First option will probably replicate natural browser behavior and quirks better, second is kind of hacky and probably has unforeseen edge cases. Just have to make sure whichever plays nicely with all browsers. I'm on a phone so I'll post the relevant sections of code in a following comment. |
This is the code that scrolls for Because of the way Qwik/QwikCity works, there were some subtleties and also time constraints for me that required duplicating some code on refresh/re-initialization. I haven't had time to dedupe yet, so the following code scrolls for hijacked same-page Whatever solution needs to be copied to both locations for now. (Look for |
Which component is affected?
Qwik Runtime
Describe the bug
Issue Overview
This report outlines an observed inconsistency in the behavior of the
<a>
and QwikLink
elements when used for scrolling to a target element in a Qwik application. The behavior varies between local and Stackblitz environments, and also changes after arouteAction$
is invoked upon form submission.<a>
Element BehaviorThe
<a>
element initially performs as expected, scrolling to the target element and opening thedetails
element that contains the target when clicked. However, after arouteAction$
is triggered upon form submission, subsequent clicks on the<a>
element have no effect. This behavior is consistent in both local and Stackblitz environments.Qwik
Link
Element BehaviorThe behavior of the Qwik
Link
element differs significantly between local and Stackblitz environments. In a local environment, theLink
element, despite having the same href as the<a>
element, does not respond to clicks even before form submission. Conversely, in the Stackblitz environment, theLink
element functions as expected both before and after form submission.Reproduction Steps
Both the local and Stackblitz applications share the same codebase, including the
package.json
. Detailed instructions for reproducing the issue are provided on-screen in both applications.Reproduction
https://github.com/Sport-Thieme/qwik-scroll-issue
Steps to reproduce
Qwik Scroll Issue Demo
This repository contains a demo for the Qwik scroll issue. Follow the instructions below to clone and start the repository:
Cloning the Repository
Open a terminal.
Navigate to the directory where you want to clone the repository.
Run the following command:
Starting the Repository
Navigate into the cloned repository's directory:
cd qwik-scroll-issue
Install the dependencies:
Start the application:
The application should now be running at
http://localhost:5173
.Issue Description
This repository demonstrates an unexpected behavior in Qwik related to the
<a>
element and the QwikLink
element when used for scrolling to an element with a specific id.<a>
Element BehaviorThe
<a>
element behaves as expected, scrolling to the target element and opening thedetails
element that contains the target when clicked, until arouteAction$
is called upon form submission. After the form submission, clicking on the<a>
element has no effect. This behavior is consistent both when running the application locally and on Stackblitz.Qwik
Link
Element BehaviorThe behavior of the Qwik
Link
element differs between running the application locally and on Stackblitz.Local Environment
In a local environment, the
Link
element neither scrolls to the target element nor opens thedetails
element, even before form submission.Stackblitz Environment
On Stackblitz, the
Link
element behaves as expected, both before and after form submission. It scrolls to the target element and opens thedetails
element when clicked.Testing the Issue
Detailed instructions on how to test this issue will be displayed on the screen when you run the application.
System Info
Additional Information
Please, make sure to check the behaviour both on Stackblitz and by running the app locally after cloning it.
The text was updated successfully, but these errors were encountered: