View Transition API: keeping parts untouched #717
Replies: 4 comments 3 replies
-
|
Thanks @florian-lefebvre for the summary of our journey. The basic idea of view transitions is to have two pages and have a smooth transition from page A to page B. Unfortunately, this state preservation doesn't work for iframes because they reload their content when you move them. A valid way to deal with this would be to diff the old and new DOMs and keep the old nodes as long as they are (recursively) identic generating a sequence of deletions and insertions to the current DOM. This way, the existing iframes would stay untouched and their content would be preserved. On the other hand, iframe elements seem to be the only elements that loose their state by being copied over. |
Beta Was this translation helpful? Give feedback.
-
|
Apparently this is running into a limitation of Here's a relevant StackOverflow discussion from almost 12 years ago. 🫠 |
Beta Was this translation helpful? Give feedback.
-
|
With the limitation that the iframe is structural in the same position in both documents, we can keep the parents and swap the remainder of the document around that. I will give that i try. |
Beta Was this translation helpful? Give feedback.
-
|
I'm closing the proposal as this component by Martin allows this use-case |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Body
Summary
Add the ability to mark areas of the page to stay untouched between transitions.
Background & Motivation
This proposal comes after an interesting discussion with @martrapp over on Discord (see thread).
Usecase
A common pattern with web apps is to add frame-based widget, with tools like Intercom or Algomo. You add a script, it injects a frame, all good! Well, that's not that easy with the VT API.
Problem
1st "issue" is that the iframe is removed when a transition is triggered, which is the default behavior. Then, solution here is to create it programmatically (even though it's not super DX if you have to do that for every widget):
So that's great but the widget disappear and reappear on transition. Feels a bit weird 🤔.
Then @martrapp told me we can add some placeholders divs with the
transition:persistattribute once, and "swap" them by adding thedata-astro-transition-persistattribute to the iframe. The code becomes quite complicated at this point:And it kinda works: iframe are persisted! Well...yes but know. There is still the annoying flicker.
@martrapp investigated:
Goals
Example
We can maybe learn from other frameworks like Nuxt.
The implementation could look like:
The name is really bad here but you get the idea
Beta Was this translation helpful? Give feedback.
All reactions