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

The preload function of a page is called even if preventDefault is called on onclick, onmousedown and ontouchstart on a data-sveltekit-preload-data="tap" anchor #12510

Closed
kran6a opened this issue Jul 28, 2024 · 0 comments · Fixed by #12887
Labels
bug Something isn't working

Comments

@kran6a
Copy link

kran6a commented Jul 28, 2024

Describe the bug

I found this odd behaviour when using an anchor element that included a child that should not trigger navigation. Tried doing event.preventDefault on the child as it prevents the navigation but still calls the preload function.

I don't think it is the intended behaviour as the fetched data is not used for the (cancelled) navigation and might be stale if a later navigation happens.

It is a one line fix. Just checking event.defaultPrevented here would prevent the preloading.

Reproduction

Was not able to run the https://node.new/sveltekit with the latest svelte v5 and sveltekit versions but I think the bug is obvious as the mousedown and touchstart listeners are attached just a few lines below the tap() function and there is no event.defaultPrevented check on any of them, unlike the click event, which is checking it here.

Logs

No response

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (12) x64 AMD Ryzen 5 3600XT 6-Core Processor
    Memory: 19.54 GB / 63.93 GB
  Binaries:
    Node: 22.5.1 - C:\Program Files\nodejs\node.EXE
    npm: 10.8.2 - C:\Program Files\nodejs\npm.CMD
    pnpm: 9.6.0 - C:\Program Files\nodejs\pnpm.CMD
    bun: 1.1.21 - ~\.bun\bin\bun.EXE
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @sveltejs/adapter-static: ^3.0.2 => 3.0.2
    @sveltejs/kit: ^2.5.18 => 2.5.18
    @sveltejs/vite-plugin-svelte: ^3.1.1 => 3.1.1
    svelte: 5.0.0-next.200 => 5.0.0-next.200
    vite: ^5.3.5 => 5.3.5

Severity

annoyance

Additional Information

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants