- Notifications
You must be signed in to change notification settings - Fork238
Implement backward and forward navigation options to iframed window (1.5 - accidentally closed)#191
Uh oh!
There was an error while loading.Please reload this page.
Conversation
@brandonmcconnell is attempting to deploy a commit to theSvelte Team onVercel. A member of the Team first needs toauthorize it. |
Copying my comments that I added to PR#181 since it was merged: |
@Rich-Harris, I think the reload is primarily caused by the iframe being removed and re-added to the screen and how that change interacts with the bwd/fwd history changes. According to the comment inside the /**@param {string} path */functionset_iframe_src(src){// removing the iframe from the document allows us to// change the src without adding a history entry, which// would make back/forward traversal very annoyingconstparentNode=/**@type {HTMLElement} */(iframe.parentNode);iframe.classList.remove('loaded');parentNode?.removeChild(iframe);iframe.src=src;parentNode?.appendChild(iframe);} …removing the iframe altogether and re-injecting it to the page is supposed to "change the src without adding a history entry" though I do not see that actually working in Chrome, even before my PR. Does that work in other browsers? As I navigate around one iframe, I still have to click the browser's back button repeatedly to traverse through every navigation from the iframe. I can confirm that removing the Let's go ahead and revert this PR for now, and either re-open this PR or I can create a new PR that builds on this one and addresses those concerns. |
brandonmcconnell commentedJan 23, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@Rich-Harris@dummdidumm One idea here which might remove much of the complexity around this is to sync the iframe history/URL state with the browser's so that as the iframe's URL changes, there could be URL param in the browser like I'm not sure if/how/where/when |
heads up: when#189 is merged code will be shuffled around quite a bit, your code would go into |
brandonmcconnell commentedJan 23, 2023 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Oops, well I didn't intentionally close this PR. Probably happened automatically when I re-synced with the latest master. I'll open a new one with the changes. |
Uh oh!
There was an error while loading.Please reload this page.
Note: This PR builds on the merged and soon-to-be-revertedPR #181 and removes the
set_iframe_scrfunction andloadedarchitecture so that the app navigates backward and forward seamlessly.Overview of changes
This PR adds backward and forward navigation options to iframed window. Because this sort of behavior isn't normally possible within the natural constraints of the History API since the history of the iframed window and that of its containing parent window operate together, I opted to manually track the history of the iframed window in two arrays—
history_bwdandhistory_fwd.Implementation/test cases & detailed steps for each
When any path is manually entered into the iframe's simulated address field…(expand to see details)
pathis appended tohistory_bwdhistory_fwdis resetpathis naturally set to the entered path (current functionality)When the "back" button is clicked…(expand to see details)
pathis prepended tohistory_fwdhistory_bwdis sliced offpath) replaces the currentpathWhen the "forward" button is clicked…(expand to see details)
pathis appended tohistory_bwdhistory_fwdis sliced offpath) replaces the currentpathWhen any link within the iframe is clicked, it is picked up by
handle_messagewhich then falls back to using thenav_tofunction for handling and tracking the history accordingly, effectively…(expand to see details)pathis appended tohistory_bwdhistory_fwdis resetpathis naturally set to the entered path (current functionality)Notes
reset_historyfunction that resets the history, which I trigger in thetryclause withinafterNavigate.Testing
This can be tested/demoed effectively using any of the routing examples:
Screen recording
Screen.Recording.2023-01-23.at.11.51.15.AM.mov