Skip to content

Commit d24192e

Browse files
committed
Document usage with SPA libraries like Turbo (Fixes #219)
1 parent 5b5ce49 commit d24192e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

docs/interface/js/_index.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,13 @@ codeInputElement.addEventListener("code-input_load", () => {
2222
```
2323

2424
For backwards compatibility, you should also implement the subset of the functionality that doesn't require `code-input.js` on the `<textarea data-code-input-fallback>` element before load, if you have one. For backwards compatibility and technical reasons, event handlers registered in HTML attributes like `onchange` of the textarea will be passed to the code-input element when it is registered, but event listeners registered like that above will not - this should be cleaned up in major version 3.
25+
26+
## Caching in Single-Page Applications
27+
28+
Some JavaScript Single-Page App libraries, such as [Turbo](https://turbo.hotwired.dev/), will try to cache the `code-input` element and render it again on the page in the same state as when it was cached. This can break functionality, but that is easy to fix.
29+
30+
Run this code ***just before*** any `code-input` elements are ***cached*** (in Turbo, on the `turbo:before-cache` event):
31+
32+
```javascript
33+
document.querySelectorAll("code-input textarea").forEach((el) => el.setAttribute("data-code-input-fallback", true));
34+
```

0 commit comments

Comments
 (0)