jack
Explore posts from serversuseSubmission pending state resolves on url change?
i have some optimistic ui, with roughly the following structure:
then somewhere else i use
useSubmission(save)
and disable buttons based on pending
state as i don't want user's editing lists that aren't accurate to server state.
the weird thing is, when i include the logic above with the **
, the useSubmission state basically dies. it returns to undefined, and my buttons are don't disabled
if instead i wait to set view -> "read"
until after i've checked the result of the server call, then the pending
state works perfectly (which i can't really do, otherwise the illusion of the optimistic ui is gone)
wondering if this is expected, or perhaps i'm doing something wrong? I can post code tomorrow if this doesn't make sense, thanks!6 replies
does any sort of primitive similar to Show for non-jsx use exist?
i had Claude generate most of this function for me. wondering if there's a solution/pattern for this problem, as well as if this is a horrible idea and i'm missing some case as to why
so that i can write signals with async inputs a bit easier:
previously i'd have to either do some sort of type guard/narrow manually each time in the function passed here which isn't great, or I just do like
user()?id ?? ""
, but i don't really want to be passing empty string down as a fallback, i'd rather do nothing until user()?.id is valid1 replies
use of cache causing page not to render at all on client nav
been struggling with this for like 2 hours and finally narrowed down that if any single cache() call exists in my file, my page just won't render it's content (at least on client)
i have no idea why this is happening, and i'm not really sure at what point this began to happen. wondering if there are any common symptoms for this
4 replies
derived, but update-able, signal?
is it possible to have a piece of reactive code that can be updated directly, but is also tied to another piece of state?
I have a list I fetch from server that is wrapped with createAsync. I want to use this to track server state, but then have a dup of that list that can be updated any number of times in the app. The user then hits save, and we update the list on server and revalidate
I originally just tried a derived signal, but I can't directly update this. Then I was thinking of just making another signal and having it's initial value be a call to its initial value, but I'm not sure if this is a good thing to do
any idea?
47 replies
nested layout
is it possible to make the file structure like follows:
obviously
layout.tsx
isn't the proper naming convention, but just wondering if it's possible to achieve something like that. Currently I'm doing
but routes/ is gets pretty cluttered fast as I create route groups3 replies
TTCTheo's Typesafe Cult
•Created by jack on 7/26/2024 in #questions
<img /> flicker on transition when conditionally rendering separate lists
![No description](https://cdn.answeroverflow.com/1266265555728465994/image.png)
2 replies
TTCTheo's Typesafe Cult
•Created by jack on 3/17/2024 in #questions
revalidate cached data on page load app router?
if i fetch a user's profile data with unstable_cache, but in case a user updates their data since last cache, i want to get that update data. is their a way (i believe RQ worked this way) so that you rely on the cached data on page load, but then it refetches in the background and updates if it's new?
i came up with this seemingly really hacky client comp that will revalidate the path on page load. i just mount it in the page component. wondering if anyone has a better approach. I might just default to not using unstable_cache, and just always fetch new data
3 replies
TTCTheo's Typesafe Cult
•Created by jack on 12/27/2023 in #questions
discriminated union as props
is there anything noticeably wrong with this , when used like
I'm getting a "false is not assignable to boolean" error, but I thought this would be the only way to use discrimnated union to type narrow properly here.
2 replies
type narrowing signals
I've got some state (I'm making a card game) that looks like
and then my signal to track game state ends up looking like
over time, i want to update this object. since i'm using discriminated types, if i want to reason about any of the props that only exist on
GamePaused
or GameOver
, I need to do some narrowing.
it seems like doing a if (gameState().state !== "playing") { return } ... gameState().___
doesn't successfully autocomplete. I'm assuming that typescript doesn't have enough info to guarantee that the 2nd getter invocation will be equivalent to that of the first.
Next reasonable idea is to invoke the getter once and store in a variable, then use that to type narrow. But then when I do a setGameState(...) using that variable, I'm not following the nested reactivity pattern here https://www.solidjs.com/tutorial/stores_nested_reactivity
Any thoughts/best practices here ?16 replies
TTCTheo's Typesafe Cult
•Created by jack on 11/12/2023 in #questions
type wizard help needed for my fake trpc package
I kinda gave up on tRPC with app router cuz I got frustrated BUT I really like using tRPC. I appreciate that it's organized (but not too restrictive like a rest server) and the method by which inputs are passed and parsed.
As such, I started working on a way in my app to define things almost exactly like a trpc router/procedure so that you still get input parsing with zod, type safety updates on definition and caller side, but just without the trpc stuff. At this point it's not even worth it, but I'm too invested and want it to work. This is majority of the code
which can then be used like this (where i nest it a few times)
this works surprisingly well, however, it's not inferring return type properly. I just get
unknown
, which makes sense since my fn types define the return as such. Anyone have thoughts?3 replies
TTCTheo's Typesafe Cult
•Created by jack on 11/11/2023 in #questions
upgraded to new ct3a; all trpc calls throwing 'Unexpected token r in JSON at position 0'
![No description](https://cdn.answeroverflow.com/1172690259172151426/image.png)
13 replies
TTCTheo's Typesafe Cult
•Created by jack on 11/8/2023 in #questions
including /edit path for profile data?
i have a url
/username
and this has a list of data that can be re-ordered and edited. my plan was to have it such that you click edit, the list becomes re-orderable and you reorder, then you click save and it persists to the server.
thoughts on having the readonly state being /username
and the editable state being /username/edit
? i'm pretty uncertain if i like this approach or not.
another option is to have the list always in re-orderable state, and just save with a slight debounce or whatever7 replies
TTCTheo's Typesafe Cult
•Created by jack on 11/2/2023 in #questions
help interleaving server/client comps in layout?
![No description](https://cdn.answeroverflow.com/1169427350518235286/image.png)
31 replies
TTCTheo's Typesafe Cult
•Created by jack on 10/25/2023 in #questions
trpc/app-router surfacing trpc errors in `error.tsx`?
[i already posted this on trpc discord but not getting anything over there so figured i'd see if anyone here might know]
I've got this condition for throwing in my trpc procedure:
and on client I have a next13
error.tsx
route, in which I do:
errorCode
is always 500 when we throw from that condition. No matter the code I pass when I throw5 replies
error route always getting 500 from trpc error? (next13/approuter)
I've got this condition for throwing in my trpc procedure:
and on client I have a next13
error.tsx
route, in which I do:
errorCode
is always 500 when we throw from that condition. No matter the code I pass when I throw2 replies
TTCTheo's Typesafe Cult
•Created by jack on 10/20/2023 in #questions
t3app app router; catching errors in trpc route called from rsc?
iirc, in old react/trpc (pages with trpc w/ RQ), the return object had all sorts of statuses etc, including an error status. From there, if trpc throws an error, you can just handle it on client with out muddying the trpc procedures with try/catch?
i'm admittedly using the beta ct3a build from a month-ish ago, so this might be addressed, but right now if a dependency call (clerk sdk in this case) throws an error in my procedure, this just surfaces on the client. am i just forced to try/catch in one place or another since we don't get any of the RQ state magic on server side? if so, where would be the best place to handle it? I really liked the simplicity of trpc in pages router and just a quick client check to see if we have encountered an error or not. I guess this wouldn't change in this case? wrap my trpc call in try catch and render accordingly; even though this technically isn't on the client, it still maintains the majority of the mental model of call trpc from component -> handle error and show appropriate view.
looking for suggestions on this!
3 replies
DTDrizzle Team
•Created by jack on 9/28/2023 in #help
dynamically insert either single object or array of objects breaking types
So here's 3 renditions of the same fn
Counterintuitively, the first two seem to work fine (not getting yelled at by typechecker), but the third, which I think to be entirely valid TypeScript, gives me a
No overload matches this call. Overload 1 of 2,...
Any idea on this? Is it something to do with the uncertain shape of the incoming parameter that it can't handle or something1 replies
TTCTheo's Typesafe Cult
•Created by jack on 7/4/2023 in #questions
easiest way to convert shadcn css vars to a different tailwind swatch?
i've got all of the css vars auto gen'd, and i'm frankly just too lazy to manually identify which value of slate that each of these correspond to and then manually replace them with a different swatch. is there a not super annoying way to do so? my next option is to write some cursed python parsing lol
2 replies