Skip to content
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

fix: better iframe navigation #193

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

dummdidumm
Copy link
Member

alternative to #187 which keeps the back/fwd navigation while also fixing the weird history pollution from iframe to parent (which was there regardless of the back/fwd navigation feature)

  • uses postMessage to trigger the inner SvelteKit's goto method
  • monkeypatches iframe's history.pushState to use replaceState instead to not create history entries, keeping the parent window's navigation order intact

- uses postMessage to trigger the inner SvelteKit's goto method
- monkeypatches iframe's history.pushState to use replaceState instead to not create history entries, keeping the parent window's navigation order intact
@vercel
Copy link

vercel bot commented Jan 24, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated
learn-svelte-dev ✅ Ready (Inspect) Visit Preview 💬 Add your feedback Jan 24, 2023 at 7:44PM (UTC)

@Rich-Harris
Copy link
Member

This will break any tutorials that involve navigation.type, no?

@Rich-Harris
Copy link
Member

(I think we should undo #181 and work on this at leisure, rather than leaving the current UI in place any longer)

@dummdidumm
Copy link
Member Author

What do you mean by navigation.type?
(if you're nervous keeping the current state active we can do revert first if you want)

@Rich-Harris
Copy link
Member

In beforeNavigate and afterNavigate etc — navigation.type should be popstate but will be link https://kit.svelte.dev/docs/types#public-types-navigationtype. I'll do the revert, then we can figure this stuff out later

@dummdidumm
Copy link
Member Author

Ah I see. We could

  • just not worry about this case in the respective tutorial
  • specifically disable the pushState hack and use pop/push delta commands instead of goto for that tutorial
  • disable the pushState hack and use pop/push delta for all tutorials (with the drawback that it pollutes the parent history like before)

I don't think that should hold us back though, since without this feature there wouldn't even be a way to trigger the popstate navigation type within the iframe.

@brandonmcconnell
Copy link
Contributor

brandonmcconnell commented Feb 6, 2023

@dummdidumm @Rich-Harris Another idea could be to allow the iframe state to work naturally until we see some movement on whatwg/html#6501. That meaning, we could mesh the iframe history with the window's history and have window preserve the iframe state by storing the iframe's current path in a URL param, like…

https://learn.svelte.dev/tutorial/pages?path=/about

That way, it's not so much pollution as it is standard history tracking where there are no redundant polluted entries, but a bunch of unique entries that are all meaningful when they occur.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants