Skip to content

Instantly share code, notes, and snippets.

@secretpray
Last active May 5, 2024 03:32
Show Gist options
  • Save secretpray/2b72a41d3d08200967fcf7a7481944d9 to your computer and use it in GitHub Desktop.
Save secretpray/2b72a41d3d08200967fcf7a7481944d9 to your computer and use it in GitHub Desktop.
 fetch(href, {
      headers: {
        Accept: "text/vnd.turbo-stream.html",
      },
    })
      .then(r => r.text())
      .then(html => Turbo.renderStreamMessage(html))
//  optionally reflect the url    .then(_ => history.replaceState(history.state, "", href))
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
  static values = {
    src: String,
  }

  connect() {
    fetch(this.srcValue, {
      headers: {
        Accept: "text/vnd.turbo-stream.html",
      },
    }).then(r => r.text())
      .then(html => Turbo.renderStreamMessage(html))
  }
}
@secretpray
Copy link
Author

async uploadFileToServer(file) {
  // ...
  const response = await fetch("/test/upload", {
    // ...
  })
  
  const html = await response.text()
  Turbo.renderStreamMessage(html)
}

@secretpray
Copy link
Author

Turbo.visit(url, { frame: '_top', action: 'advance' })

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment