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

preloadCode errors during page load #13297

Open
WaltzingPenguin opened this issue Jan 9, 2025 · 1 comment
Open

preloadCode errors during page load #13297

WaltzingPenguin opened this issue Jan 9, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@WaltzingPenguin
Copy link

Describe the bug

Calling preloadCode during initial page load results in

TypeError: Failed to construct 'URL': Invalid base URL

This issue is present in @sveltejs/kit version 2.15.0 but not present in 2.14.0

Reproduction

https://github.com/WaltzingPenguin/sveltekit-preloadCode/tree/main/src/routes/login

  • Create a new SvelteKit project
  • Create src/routes/login/+page.svelte with any content
  • Create src/routes/login/+page.ts with
import { browser } from "$app/environment";
import { preloadCode } from "$app/navigation";
import { base } from "$app/paths";

export function load() {
  if (browser) {
    preloadCode(base)
  }
}
  • Run the dev server and navigate directly to /login

Logs

No response

System Info

System:
    OS: Windows 11 10.0.22631
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i5-13600KF
    Memory: 39.54 GB / 63.85 GB
  Binaries:
    Node: 20.9.0 - C:\Program Files\nodejs\node.EXE
    npm: 10.1.0 - C:\Program Files\nodejs\npm.CMD
    pnpm: 8.11.0 - ~\AppData\Local\pnpm\pnpm.CMD
  Browsers:
    Edge: Chromium (127.0.2651.74)
    Internet Explorer: 11.0.22621.3527
  npmPackages:
    @sveltejs/adapter-static: ^3.0.8 => 3.0.8
    @sveltejs/kit: ^2.15.2 => 2.15.2
    @sveltejs/vite-plugin-svelte: ^5.0.3 => 5.0.3
    svelte: ^5.17.3 => 5.17.3
    vite: ^6.0.7 => 6.0.7

Severity

blocking an upgrade

Additional Information

No response

@eltigerchino
Copy link
Member

eltigerchino commented Jan 10, 2025

Calling preloadCode in load in the browser doesn't seem to work in 2.14.0 either.

The issue is that preloadCode relies on current.url but that isn't populated until after the load functions are run.

preloadCode is called when the nodes are loaded

return load_node({

but current.url is only populated much later when we call initialize

current = result.state;

@eltigerchino eltigerchino added the bug Something isn't working label Jan 10, 2025
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

No branches or pull requests

2 participants