klembot / chapbook

A simple, readable story format for Twine 2.
https://klembot.github.io/chapbook
MIT License
80 stars 25 forks source link

changeContent breaks links #216

Open massette opened 1 month ago

massette commented 1 month ago

Describe the bug Concurrent calls to <content-element>.changeContent permanently remove all event handlers from the element.

To Reproduce Add the following passage to a story and click the cycling link.

[JavaScript]
const body = document.querySelector("body-content");

window.addEventListener("click", () => {
    body.changeContent(() => {});
});

[continue]
{cycling link, choices: ["A", "B", "C"]}

[[This link will break->Other Passage]]

Expected behavior Event handlers are consistently restored after changeContent triggers a transition, regardless of the state of the page when it is called.

Stories and screenshots changeContent-issue.zip

Environment Problem observed on Windows 11 version 23H2 in Microsoft Edge version 128.0.2739.79.

david-donachie commented 1 month ago

As described on the Twine Discord, this looks like a race condition between two instances of changeContent(), one triggered by the cycling link, one by the user-added listener.

The sequence seems to be:

It feels like either changeContent() needs a queue, or multiple instances called on the same element need a way to share the off-screen buffer rather than recreating it.