How to track "in-progress" frontend state? #1544
Unanswered
adamcunnington-mlg
asked this question in
Q&A
Replies: 1 comment 10 replies
-
Or maybe I'm over complicating this and html forms are fine and I just have to be careful when refreshing PARTS of the form so I don't lose any state. All "in-progress" tab state will be in the DOM and I can just select the bits that I want when posting? |
Beta Was this translation helpful? Give feedback.
10 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
By "in-progress" state, I'm talking about a user interacting on some frontend web page and progressively doing stuff; filling out a form, adding rows to a table, deleting rows etc. etc. etc. Eventually they are going to click "Submit" or "Save" but until that point, I'm trying to figure out how one manages such state in an HTMX-app context where I am trying to avoid writing javascript.
In a SPA, frontend manages all state in browser memory via javascript - redux and the like.
In a MPA, backend manages all state. Frontend posts state via html form. This is straightforward though because the page's structure is not dynamic so the HTML form can keep track of "in-progress" state and then post when ready.
With HTMX, as far as I can understand, we're sort of in a half-way house. Technically, it's an MPA but we're refreshing parts of the page via AJAX and thus, my frontend user-input is of a dynamic structure.
As far as I can tell, every time the user does something in the frontend - iterating on their "in-progress" state, the frontend must send this to the backend and the backend must keep track. The backend could store in session cookie, backend in-memory cache or persistent store (likely not this though as the data is not yet "submitted") but aside from other challenges, I am stumbling over the very first hurdle which is how can the backend actually RELATE state from a particular "context". If I open 3 tabs and have 3 concurrent "in-progress" journeys, however I choose the store the "in-progress" state, I need to be able to know which one relates to which. So I need some sort of deterministic key that the frontend can use to only grab it's state. But what could such a deterministic key be? I've not inserted anything into a database yet and some "request id" isn't good enough. I need "tab id"!
The only option I can think of is perhaps using a websocket - I don't know much about this beyond the general way in which it works - but is that the right way to keep track of progressive state?
I feel like my scenario is a really common one but the solution is really unobvious to me. Is the answer simply "well, this is where you actually do need to use javascript and you should do that alongside htmx - perhaps redux".
Help! Thanks!
Beta Was this translation helpful? Give feedback.
All reactions