derrickreimer / fathom-client

A Fathom Analytics library to help with client-side routing
http://npm.im/fathom-client
MIT License
177 stars 18 forks source link

Avoid `Type error: 'searchParams' is possibly 'null'.` in example code #56

Closed unitof closed 4 months ago

unitof commented 4 months ago

Out of the box (on next@14), the app router example code fails to build with a Type error, since searchParams can be null:

./app/Fathom.tsx:25:23
Type error: 'searchParams' is possibly 'null'.
  23 |
  24 |     trackPageview({
> 25 |       url: pathname + searchParams.toString(),
     |                       ^
  26 |       referrer: document.referrer
  27 |     });
  28 |   }, [pathname, searchParams]);
Error: Command "npm run vercel-build" exited with 1

This allows for that with the optional chaining ?. operator.

derrickreimer commented 4 months ago

Thanks @unitof!