question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`$page.url.pathname` represented as "//prerender/" when building using the static adapter

See original GitHub issue

Describe the bug

Using the latest versions:

In development, $page.url.pathname in routes/index.svelte will correctly be displayed as “/”.

However, when building for production using the static adapter, the same route is represented as “//prerender/”.

Inspecting build/index.html, the markup has the correct “/” but the script that hydrates the markup has the following:

<script type="module">
  import { start } from "/_app/start-40ff21d5.js";
  start({
    target: document.querySelector("#svelte"),
    paths: { base: "", assets: "" },
    session: {},
    route: true,
    spa: false,
    trailing_slash: "never",
    hydrate: {
      status: 200,
      error: null,
      nodes: [
        import("/_app/layout.svelte-96b29dd0.js"),
        import("/_app/pages/index.svelte-91ca303b.js"),
      ],
      url: new URL("sveltekit://prerender/"),
      params: {},
    },
  });
</script>

Evaluating new URL("sveltekit://prerender/") shows that the URL.pathname is //prerender/.

Workaround

A workaround is to explicitly set kit.ssr or kit.hydrate to false.

Reproduction

https://github.com/metonym/sveltekit-page.url.pathname

Logs

No response

System Info

System:
  OS: macOS 11.4
  CPU: (8) x64 Intel(R) Core(TM) i5-8257U CPU @ 1.40GHz
  Memory: 19.40 MB / 16.00 GB
  Shell: 5.8 - /bin/zsh
Binaries:
  Node: 16.13.1 - ~/.nvm/versions/node/v16.13.1/bin/node
  Yarn: 1.22.17 - /usr/local/bin/yarn
  npm: 8.1.2 - ~/.nvm/versions/node/v16.13.1/bin/npm
Browsers:
  Chrome: 96.0.4664.110
  Firefox: 89.0.2
  Safari: 14.1.1
npmPackages:
  @sveltejs/adapter-static: next => 1.0.0-next.24 
  @sveltejs/kit: next => 1.0.0-next.211 
  svelte: ^3.44.0 => 3.44.3

Severity

blocking an upgrade

Additional Information

No response

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:4
  • Comments:12 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
brittneypostmacommented, Jan 23, 2022

Same here, after updating to latest, this issue seems to have been resolved.

1reaction
metonymcommented, Jan 15, 2022

I updated the repro to use the latest SvelteKit (v1.0.0-next.231) and also added console.log($page.url.pathname) to routes/index.svelte. I’m no longer seeing this error.

After building using the static adapter, I see “/” in the console, as expected.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I fix this error when trying to deploy my svelte app on ...
The issue is that you're linking to /src/images/github.png in index.svelte but the prerenderer can't find the file because it tries to look ...
Read more >
Having some problems with static adapter & site generation ...
I've tried several things using await blocks, load function, This is what I currently have, and when I do npm run build the...
Read more >
Configuration • Docs • SvelteKit
Your adapter is run when executing vite build . ... 'my-file': 'path/to/my-file.js', ... When pages are prerendered, the CSP header is added via...
Read more >
Static Site Generation and Server-Side Rendering Using Next.js
As we said earlier, serving empty pages is not acceptable for an application that hugely relies on its content. What we want to...
Read more >
Let's learn SvelteKit by building a static Markdown blog from ...
This is a walkthrough of using SvelteKit to set up a prerendered static blog with Markdown, Sass and an API. (That's how this...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found