Skip to content

Turbo compatibility #219

@excid3

Description

@excid3

I was looking at using this in a Rails app that uses Turbo on the frontend. Turbo intercepts page visits and handles them with fetch to give an SPA-like experience. Turbo maintains an internal page cache, so the injected HTML needs to be cleaned up.

This causes a problem because if you render a code-input, navigate to another page, then hit the Back button, the code-input renders with the HTML

Image

I can get most of the way there by removing all the non-textarea elements before cache using the following but it still leaves the textarea HTML in the code like you see in the above screenshot.

document.addEventListener("turbo:before-cache", () => {
    document.querySelectorAll("code-input :not(textarea)").forEach((el) => el.remove())
})
    <code-input class="line-numbers code-input_autogrow_height" language="bash">
      <%= form.text_area :body, class: "form-control", rows: 12, data: { code_input_fallback: true } %>
    </code-input>

I think this comes down to how the textarea[data-code-input-fallback] is handled since that attribute seems to be removed.

this.innerHTML = this.escapeHtml(value);

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:coreA bug/feature for the core code-input.js/code-input.css filesarea:externalA bug/feature due to integration with another library / JavaScript framework, but not the browser.bugSomething isn't workingpriority:mediumstatus:workedaroundA workaround has been sent.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions