Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong target on turbo:before-fetch-request event for links with data-turbo-stream #1336

Open
alexandergitter opened this issue Nov 11, 2024 · 0 comments

Comments

@alexandergitter
Copy link

alexandergitter commented Nov 11, 2024

Consider the following example document:

<!DOCTYPE html>
<html>

<script src="https://cdn.jsdelivr.net/npm/@hotwired/turbo/dist/turbo.es2017-umd.min.js"></script>

<body>
  <a id="link" href="/test" data-turbo-stream="true">Click me</a>
  
  <script>
    document.getElementById("link").addEventListener("turbo:before-fetch-request", (ev) => console.log("link", ev))
    document.addEventListener("turbo:before-fetch-request", (ev) => console.log("document", ev))
  </script>
</body>

</html>

This has an <a>-tag with the data-turbo-stream attribute, so that Turbo does a Turbo Stream request to the given URL.
Note that I added event listeners for turbo:before-fetch-request on both the link itself as well as on the document.

I would expect the event to fire on the link (which it isn't), or at least for the link to be referenced in the event object somewhere (e.g. as the target or somewhere in detail).
Instead, the event's target is some random form that is not part of the original document (probably added by Turbo temporarily?) and there's no indication that the event actually got triggered via the link.

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

No branches or pull requests

1 participant