-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Fast Scroll Can Cause HTMX reveal event To Fail #463
Comments
Stack from the console using the htmx code from the non-minified version of htmx on GitHub:
|
FWIW as an experiment I tried changing to hx-swap="afterend settle:1s" and adding the settle:1s made it much, much quicker to die with the same stack. Changed to settle:0s and it won't generate the error no matter how fast I scroll. |
@benpate You interested in looking into this one? |
Yes. I will give it a try. Thank you for the test code. That should make this easier to find/fix. I experienced a similar issue with an older version of this code and went looking for a solution. It seems like it works "mostly" but not all the way. |
First, I'm sorry it's taken me some time to take a look at this. But, I finally did, and here's what I found.
I'm not very familiar with the Java templating engine you're using, but it seems like the issue is on line 17 of your demo code which uses |
RE: taking time, no worries. Fix my bug in your open source project now! haha no. The infinite-scroll.html is a Thymeleaf template. All the th:hx-get version does is rewrite the URL inside a bit for server config. I just checked in a version that doesn't do that - for a local test it makes no difference. The infinite-scroll.html version is the initial load. The version that comes back to the server is actually coming from the controller. Looking at it more closely, I think it might be as dumb as malformed html coming back from the controller. Hmm. |
Cool :). Kick it around and let me know if you need more help? |
Ok, I poked at it some more, and the HTML in the current version is now valid. Can you check on your end using a version that doesn't use the built-in JS local server? I suspect that might be causing the threading to sync in the browser in a fashion that's not representative of a "real" server. You can replicate with my demo example by installing JDK 16 & Maven and just running Here's the entire rendered html base:
... and here is a sample of the response...
Let me know if that is enough to replicate. Probably could literally replicate with these as raw HTML in an |
Oh, and the web jars stuff is just a fancy Java way of managing/referencing NPM libraries that have been turning into Maven (Java build tool) dependencies. |
So, I can't replicate it with my MacBook Pro trackpad scrolling, but I can with an eternal Logitech scrolling mouse. What. |
What. Yeah, that's pretty weird, but we're looking at a pretty specific issue. I'll try to replicate on my machine using a separate web server. I also have a MacBook, but have only tested with an Apple Mouse. I'll try with a couple of PC mice, to see if that affects things. We might be dealing with a specific incompatibility related to smooth scrolling. Separately, I really like the way htmx gives us a "revealed" trigger to work with, but its essentially a synthetic event on that node that's generated inside the library. To maintain compatibility with IE11, we're using a less efficient way of watching for scroll events. I may be needing something more powerful soon (for instance, to let me know when something scrolls OFF of the page, too) and I'm thinking about an extension or separate JS library that would trigger events. If I end up with anything useful, I'll try to publish it for the htmx community, too. |
Hey @wiverson - I'm still getting the same results no matter what I try. I've reworked the demo to load 100 page fragments from an external web server (not sinon.js). The code looks like this <div class="panel" hx-get="http://localhost/page/0" hx-trigger="revealed" hx-swap="innerHTML settle:1s"></div>
<div class="panel" hx-get="http://localhost/page/1" hx-trigger="revealed" hx-swap="innerHTML settle:1s"></div>
<div class="panel" hx-get="http://localhost/page/2" hx-trigger="revealed" hx-swap="innerHTML settle:1s"></div>
<div class="panel" hx-get="http://localhost/page/3" hx-trigger="revealed" hx-swap="innerHTML settle:1s"></div>
<div class="panel" hx-get="http://localhost/page/4" hx-trigger="revealed" hx-swap="innerHTML settle:1s"></div>
<div class="panel" hx-get="http://localhost/page/5" hx-trigger="revealed" hx-swap="innerHTML settle:1s"></div>
<div class="panel" hx-get="http://localhost/page/6" hx-trigger="revealed" hx-swap="innerHTML settle:1s"></div>
<div class="panel" hx-get="http://localhost/page/7" hx-trigger="revealed" hx-swap="innerHTML settle:1s"></div>
<div class="panel" hx-get="http://localhost/page/8" hx-trigger="revealed" hx-swap="innerHTML settle:1s"></div>
<div class="panel" hx-get="http://localhost/page/9" hx-trigger="revealed" hx-swap="innerHTML settle:1s"></div>
...
Everything still loads quickly after I scroll to a new section of the page. Sorry, I'm going to need to kick this back to you. I think something may still be funny with your code. Perhaps you could put a warning on your website: "not compatible with Logitech mice." Maybe that would work? /s |
Yeah, external mice (LogiTech or otherwise) are pretty popular, so it's still worth triaging IMHO. I'm using a LogiTech MX Anywhere 3, FWIW. Best external mouse I've ever used, ha. I can't replicate the issue with the online demo that uses the test JS server, but I have replicated it with both a Java Spring Boot and a dumb Python HTTP server. Here is the dumb Python server version: run.sh to launch the server, http://localhost:8000/ and spin the mouse wheel and can instantly replicate. But only with the mouse. Observations:
One interesting thing I didn't know about until now: WheelEvent is a thing. So perhaps this is all due to some events getting fired related to wheel events? Some potentially interesting links I found just now looking at this a bit.
Perhaps this is an issue with HTMX and scrolling/mouse wheel events? |
Event trace that fails (using the LogiTech mouse wheel): Event trace that works (using the MacBook Pro trackpad scrolling): Generated the traces by using Want me to buy you a mouse? Or if you can find the bug in the two HTML files I just sent over I'll send HTMX a donation equal to the $ for a mouse? :) |
I'll try to replicate it with your example html. That seems like the best way forward. You're very kind to offer a donation to htmx. They would go to @1cg, not to me, so I'd say do it anyway because he's awesome. But thank you, no, I'm good, I don't need a donation 😎 |
Use the HTML in the zip - I cleaned those out to make the smallest repro case I could. TBH these kinds of issues are why I prefer the JVM - I know all the gory threading internals and tools to fix there. Guess I should get off my high horse, buckle down and get into some JS analysis after all these years, ha. ;) Let me know if there is anything else I can do to help. I'm really, really curious now. My brain naturally leaps to exotic stuff like event buffer overflows or some kind of event thread sequencing issue, but who knows. 🤷♂️ |
Went ahead and fired up the debugger. Looks like the call to getInternalData is expecting a node with a verb, but for some reason that verb isn't defined. My guess is that when settle is set to zero, getInternalData is able to correctly find the result, but when settle is set to (for example) 1s there is something about the sequence of events being fired/parsing the new data/etc that's out of sync. |
Gotcha. Will do :). We'll find it. |
I've been able to reproduce this problem on my machine -- specifically using my keyboard to jump all the way to the bottom of the page while existing pages are loaded. it is failing on the same line that you've highlighted (2147 on that build, 2144 using the non-minified https://unpkg.com/htmx.org@1.3.3/dist/htmx.js) It's going to take some digging, because (as you mentioned) it's failing during the I think my first guess is the same as yours @wiverson -- that the Either of these "solutions" might work great, but will depend on some deep understanding of the underlying architecture. |
Woot! ;) |
thank you for looking into this so deeply @benpate ! I'll take over from here and see if I can come up w/ a fix. Both of you are probably onto the root cause: the request is happening before the element is fully processed. create an open source web framework they said... it'll be fun they said... 🍻 |
Done - works great now! Tested with no settle set, 0s and 2s. All works fine now.
Fame! Fortune! Glory! ^_^ ... Or at least popping up on HN once in a while. ;) FWIW, I'm working on a deck, tentatively titled "Full Stack Java Development in 2021" and htmx is going to be a cornerstone. Likely some combination of presenting at the local Java user group and/or a YouTube video. :) |
great to hear this is now working, closing this issue out |
HTMX fails with the following error in the console:
...when scrolling quickly. The code to replicate can be found at https://github.com/wiverson/htmx-demo - and the specific code generating the view can be found at:
Starting Thymeleaf View
Java Spring Boot Controller
For reference, this is using the WebJAR version of HTMX, v1.3.2.
Replicated on macOS on both Safari and Chrome.
The text was updated successfully, but these errors were encountered: