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

Query params are not available within load function with adapter-vercel #631

Closed
wiesson opened this issue Mar 24, 2021 · 2 comments · Fixed by #774
Closed

Query params are not available within load function with adapter-vercel #631

wiesson opened this issue Mar 24, 2021 · 2 comments · Fixed by #774
Labels
pkg:adapter-vercel Pertaining to the Vercel adapter

Comments

@wiesson
Copy link
Contributor

wiesson commented Mar 24, 2021

Describe the bug

It looks like that with adapter-vercel the query params within the load function are not available:

<script context="module">
  export async function load({page}) {
    console.log({page}) // page.query.URLSearchParams {} is always empty
    return {
      props: {
        query: page.query
      }
    }
  }
</script>

Logs
Vercel function log

[GET] /issues/631?q=pizza
09:45:59:38
{
  page: {
    host: undefined,
    path: '/issues/631',
    query: URLSearchParams {},
    params: {}
  }
}

To Reproduce

git clone [email protected]:wiesson/sveltekit-vercel.git
vc 

I'm assuming vercel-cli is installed and user is logged in

Expected behavior
Query parameters should be available

Information about your SvelteKit Installation:

  System:
    OS: macOS 11.2.3
    CPU: (8) arm64 Apple M1
    Memory: 204.09 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 15.12.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 7.6.3 - /usr/local/bin/npm
  Browsers:
    Chrome: 89.0.4389.90
    Firefox: 87.0
    Safari: 14.0.3
  npmPackages:
    @sveltejs/kit: next => 1.0.0-next.58 
    svelte: ^3.35.0 => 3.35.0 

Severity
The behavior is different to adapter-node

@wiesson wiesson changed the title load function does not pass queryparams with adapter-vercel Queryparams from load function are not available with adapter-vercel Mar 24, 2021
@wiesson wiesson changed the title Queryparams from load function are not available with adapter-vercel Queryparams are not available within load function with adapter-vercel Mar 24, 2021
@wiesson wiesson changed the title Queryparams are not available within load function with adapter-vercel Query params are not available within load function with adapter-vercel Mar 24, 2021
@antony antony added adapters - general Support for functionality general to all adapters pkg:adapter-vercel Pertaining to the Vercel adapter labels Mar 24, 2021
@PatrickG
Copy link
Member

PatrickG commented Mar 24, 2021

Possible duplicate #586

To get the value of a query param, you need to use page.query.get('key').
To get all query params, like in your example, you need to use Object.fromEntries(page.query).

@wiesson
Copy link
Contributor Author

wiesson commented Mar 24, 2021

I know and I did that - for sake of simplicity, I removed all that to make the example smaller - maybe not the best idea 😅 Here is a slightly longer case:

<script context="module">
  import { writable } from "svelte/store";

  export async function load({ page }) {
    const { query } = page;
    const q = query.get("q") || "";
    console.log("load", { page })
    return {
      props: {
        q: writable(q),
        s: q,
        t: "I am a string",
        w: writable("Writable here 👋")
      },
    };
  }
</script>

<script>
  import { onMount } from "svelte";
  import { page } from "$app/stores";
  export let q = writable("");
  export let t = "";
  export let s = "";
  export let w = writable("");

  console.log($page)

  onMount(async () => {
    console.log("---");
    console.log($q);
    console.log(t);
    console.log(s);
    console.log($w);
    console.log("---");
    console.log($page)
  });
</script>

<div>s: {s}</div>
<div>q: {$q}</div>
<div>t: {t}</div>
<div>w: {$w}</div>

Here is a slightly longer example,

I expect an output like this for ?q=pizza:

s: pizza
q: pizza
t: I am a string
w: Writable here 👋

but s and q are empty when using the adapter-vercel

Example: https://sveltekit-vercel.vercel.app/queryparams?q=pizza

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg:adapter-vercel Pertaining to the Vercel adapter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants