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.

request.params not available in handle hook as docs / types indicate

See original GitHub issue

Describe the bug Request.params is null in handle hook.

Logs

To Reproduce

  1. Create a route that uses params, e.g. src/routes/[product]/index.svelte
  2. Create a hook with handle function located at src/hooks.ts
  3. Try to access request.params in handle function

Example repo: https://github.com/RaeesBhatti/svelte-params-bug

Expected behavior request.params should be available in handle function of hooks.

Stacktraces

Information about your SvelteKit Installation:

Diagnostics
  System:
    OS: macOS 11.2.3
    CPU: (16) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 535.77 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.8.0 - /usr/local/bin/node
    Yarn: 1.22.10 - /usr/local/bin/yarn
    npm: 6.14.7 - /usr/local/bin/npm
  Browsers:
    Chrome: 90.0.4430.85
    Safari: 14.0.3
    Safari Technology Preview: 14.2
  npmPackages:
    @sveltejs/kit: next => 1.0.0-next.87 
    svelte: ^3.29.0 => 3.37.0 
  • Your browser: Safari Version 14.0.3 (16610.4.3.1.7)

  • Your adapter: Cloudflare Worker but this issues comes up even in dev mode.

Severity Blocking usage of SvelteKit because I need params to fetch the right data from database.

Additional context

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kamholzcommented, Sep 2, 2021

What’s the current recommended way to deal with this? I have a bunch of endpoints with an [id] param and I need to short-circuit them and return an error if the param is not in a valid format. I was hoping to do it in handle but it looks like I need to add this boilerplate to every handler (get, post, del, etc.) of every endpoint. Is there no better way? The only way I can think of is to write a function that wraps every handler, so:

export const get = validateParams(async ({ params }) => { ... });

I suppose this is workable but seems pretty clunky.

0reactions
georgecrawfordcommented, Mar 13, 2022

See related discussion on param validators here: https://github.com/sveltejs/kit/issues/4291

Read more comments on GitHub >

github_iconTop Results From Across the Web

How can I get (query string) parameters from the URL in Next.js?
Method #1: SSR (Server-Side Rendering):​​ You should use Query Context for that page. The reason is that: this data cannot be pre-rendered ahead...
Read more >
Hooks - Apollo GraphQL Docs
Apollo Client react hooks API reference. ... Param, Type, Description ... Client's React integration, and it is not available in the core ApolloClient...
Read more >
Query Parameters - Routing - Ember Guides
Query parameters are optional key-value pairs that appear to the right of the ? in a URL. For example, the following URL has...
Read more >
Parameter Binding in ASP.NET Web API - ASP.NET 4.x
In this example, the content type is "application/json" and the request body is a raw JSON string (not a JSON object). At most...
Read more >
use-query-params - npm
React Hook for managing state in URL query parameters with easy ... TypeScript icon, indicating that this package has built-in type ...
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