rootstrap/rails_hotwire_base

View on GitHub
app/javascript/controllers/turbo_stream_controller.js

Summary

Maintainability
A
0 mins
Test Coverage
import { Controller } from 'stimulus';

export default class extends Controller {
  // eslint-disable-next-line class-methods-use-this
  injectHeaders () {
    const injectHeaders = (event) => {
      const { headers } = event.detail.fetchOptions || {};
      if (headers) {
        headers.Accept = `text/vnd.turbo-stream.html, ${headers.Accept}`;
      }
    };
    window.addEventListener('turbo:before-fetch-request', injectHeaders, { once: true });
  }
}