How to tell the server this is the first request on this div? #1931
mattwalshdev
started this conversation in
General
Replies: 1 comment
-
|
Hey, if you're replacing the whole div anyway with an element having that new <div hx-get="/url?initialRequest=true" hx-target="this" hx-swap="outerHTML" hx-trigger="load"></div>Then swapping it with <div hx-get="/url" hx-target="this" hx-swap="outerHTML" hx-trigger="every 2000ms"></div>Then you could retrieve that parameter on your backend to find out whether it's the initial request or a polled one. Hope this helps! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I have long running backend tasks that I poll a db with hx-trigger for updated info, percentage complete etc. Subsequent requests replace the outerhtml with a htmx hx-trigger="every 2000ms" attribute so it keeps checking.
It doesn't have hx-trigger="every 2000ms" poll on page load, it runs it after a form is processed, so I've had to add a hx-vals flag to tell the server this div isn't polling yet, run setup then replace with poll query.
Is hx-vals needed here, or is there a way for the server to know this is the initial state of this div? hx-vals feels like a bit of an escape hatch, so don't want to rely on it if can avoid. Does the server have access to what is listed in hx-trigger? I could see if it contains "every 2000ms" and if not, start polling.
Beta Was this translation helpful? Give feedback.
All reactions