I need to preserve DOM when going back/forward when using SPA-style navigation, either by internal links or browser1.goto
I'm doing stuff like:
browser1.goto('/hello',true)
I want that to save the current DOM, so if I click the Browser's button to go back the DOM is restored.
In other words, if you fill a form, submit, get the results in a table (dmx-repeat), and then go to another page, and then go back using the browser button, the table stays exactly as you left it.
Here's some inspiration from the HTMX project:
This creates a new history entry, allowing navigation with the browser’s back and forward buttons. htmx snapshots the current DOM and saves it into its history cache, and restores from this cache on navigation.
By default they save the DOM of <body>
Edit: As a test I tried replacing the innerHTML of an existing element and AppConnect doesn't interact with it anymore
I'll have a look at it, but with how App Connect works it will be difficult. We use the browser history so we can do partial DOM updates, the problem with the back button is that we don't have a global state for our components, each work independent of each other.
The browser component has popstate. You can also use query parameters to ensure that when the user goes back/forward, the related flows or server connects are rerun based on the parameters.
Are you storing the results from the form submission in the database? If not, why not?
Why can't you submit the form (which does processing and stores the data), then use a server connect to display the data, which you can trigger on success of the form. That way, you can also cache the results and/or just display what was saved in the database.
You can store some state in the history when navigating which you restore when you navigate back. The problem is with App Connect that the content gets re-rendered and there is no global state, each component is standalone and that makes it difficult to store some specific state.
I can take a look to just storing form element values, can't however promise anything.