hotwired / turbo

The speed of a single-page web application without having to write any JavaScript
https://turbo.hotwired.dev
MIT License
6.73k stars 429 forks source link

`data-turbo-permanent` fails when using CSS View Transitions #1048

Open rctneil opened 1 year ago

rctneil commented 1 year ago

As you can see in this thread: https://discuss.hotwired.dev/t/keep-audio-playing/5400/1

It looks like View Transitions cause my data-turbo-permanent elements to disappear and effectively not work.

I am using latest Turbo as of this post.

My View Transitions code is:

addEventListener("turbo:before-render", (event) => {
  if (document.startViewTransition) {
    const originalRender = event.detail.render
    event.detail.render = (currentElement, newElement) => {
      document.startViewTransition(()=> originalRender(currentElement, newElement))
    }
  }
})

addEventListener("turbo:before-frame-render", (event) => {
  if (document.startViewTransition) {
    const originalRender = event.detail.render
    event.detail.render = (currentElement, newElement) => {
      document.startViewTransition(()=> originalRender(currentElement, newElement))
    }
  }
})

Is there a fix or solution to this?

rctneil commented 1 year ago

Any suggestions or a fix for this?

adrienpoly commented 1 year ago

@rctneil you might want to try using View Transition with the Turn js package https://github.com/domchristie/turn as of today for me it is the most reliable implementation for page transition.

Turbo has a PR merged (https://github.com/hotwired/turbo/pull/935) for it but this is not yet part of an official release