aryzing
Explore posts from serversCreate resource TS types fail when using `{ refetching }`
When creating a resource,
the type of
value
will be Resource<unknown>
instead of Example
. However, if we delete the second arg of the fetcher and use the 1 arg version, the return type is inferred correctly.
Now value
will correctly be inferred as Resource<Example>
. Is this an issue?2 replies
Best way to pass complex values (e.g. objects) to a route?
Given a route that needs somewhat complex data, like an object, what's the best way to pass this data to the route? If multiple other areas of the app need to redirect the user to this one route, how would the pass data to it?
2 replies
Side effect in bundled code `ie(["click", "keydown"]);`
I'm trying to import types from a lib I'm building that contains a Solid.js component. However, when building using a vanilla Vite + Solid setup, the lib's build output has a top-level call to
ie(["click", "keydown"]);
. In turn, this call is added to the output build of the second package. Where is this coming from? Can Solid.js be fixed to not produce these top level function calls?39 replies
How to build styled Web Component with a CSS library?
Solid's
solid-element
is great for building Web Components. Styles inlined on components work just fine.
However, when the component starts getting complex, it's helpful to make use of some sort of CSS library. When building with Vite, many of the CSS libraries output CSS files or inject code that injects the styles in the DOM (which don't penetrate the shadow DOM boundary).
What's the best way to handle styles when building a Web Component with Solid?1 replies
Why is `BoundEventHandler` typed this way?
The type for
BoundEventHander
is,
In order to use it, I need to do something like const handler = BoundEventHandler<T,E>[0]
, note the [0]
at the end, which seems weird. Why is it typed this way? How is this type expected to be used?9 replies
How to handle auth with solid-router?
Given an app where users have access to additional routes when they are logged in, how to set up the router so that it,
- redirect users to "home" if they are logged in and happen to navigate to the login or signup page?
- redirect users to login page when visiting a route that requires authentication but they are not logged in?
Is the following a good starting point? Where would the redirects be inserted?
10 replies
How to clear a store?
From the docs, seems that setting a store's value explicitly to
undefined
will delete it from the store,
However, is there a way to clear them all in one go? If there are many keys, or the keys change, it's hard to ensure they're all getting deleted when they need to.9 replies
Solid.js Playground console doesn't support creating const / let variables
Not sure if a bug or just part of how the Playground's console works, but it doesn't allow creating
const
or let
variables. The regular browser console does. Is this a limitation of having it embedded in the playground, or a bug?
Sidenote: should there be a "Playground" support tag?1 replies
Typesafe way to render conditionally based on whether array has zero, one or many elements?
Given an array with one or more elements, the idea is to display different UIs. With React, this can be done in a typesafe way by returning different JSX after an
if
check,
How can the same be achieved with Solid? Seems that <Switch /> / <Match />
was a good place to start, although the where
's boolean check doesn't perform type narrowing, so the typecheck fails: the array could be empty and accessing the first element could return undefined
.
When adding <Show />
to the mix, the type safety can be improved,
although this seems overly verbose, and I feel uneasy about using <Show>
just for its non-null assertion. Are there better options?4 replies
Can middleware be used on a router?
Given a router where all procedures need to use the same middleware, can the middleware be somehow attached to the router instead of manually to routes?
For example, given an "admin" router, it would be quite catastrophic if one of the endpoints was accidentally set up with a
publicProcedure
instead of adminProcedure = publicProcedure.use(isAdmin)
.4 replies
Feature or happy accident: error message from `cause` being used as TRPC's error message
When a procedure throws a TRPC error with no message, it turns out that if the thrown error has a cause, and the cause has a message, the cause's message will be used as the TRPC error message returned to the client. Is this on purpose or an accident? Couldn't find this behavior documented.
2 replies
How to configure context for a standalone server?
Are there any examples out there on how to set up context for a standalone server? The docs do include an example for
next
, although it doesn't help much in setting one up for a standalone server.
How is context set up for a standalone server?6 replies
Docs hard to follow with so much `next` code
Not having a great experience with the docs. There are many examples that use
next
, making it hard to understand what should be done in cases where next
isn't being used. Take the docs on setting up the context
: https://trpc.io/docs/server/context. They're entirely next
focused. To what extent is Vercel's sponsorship affecting the docs?3 replies
How to make typed error responses in the context of a specific query?
Each query has a typed (success) response, although it seems all queries have a shared type for the error response. Is there a way of having per-query typed error responses? Is there a better alternative to having an error within a successful response, as below?
2 replies
How is a Context reactive?
The tutorial states that
Using Context has the benefit of being created as part of the reactive system and managed by itNot sure if I'm understanding this correctly. When trying to trigger reactivity, changing the context value does not seem to be re-rendering the app. However, if the context contains reactive values like signals or stores, updating their values does trigger a re-render. Therefore, would it be more correct to state that the context is not reactive, although it may contain reactive values
4 replies
Type of setStore args?
When trying to listen for any and all changes to a store value, seems the only way of being able to do so is to wrap the store's setter like so,
What is the correct type for
...args
? When typed as below, the type of the args is never
, which throws errors in the existing setters,
3 replies