S
SolidJSβ€’5mo ago
marcusbuffett

Having trouble implementing a stack of views because of the lifecycle of <Dynamic>

For my site, I have implemented a stack of views, sort of like on iOS where you can push and pop views from a shared navigation stack. But I'm having issues with how <Dynamic> renders. It's easier to show an example, so I made this minimal repro in the playground: https://playground.solidjs.com/anonymous/90d6fbd1-6114-4fb8-aa60-5c6ac104dcd3 The problem can be seen by first adding a view, then hitting "remove myself" on that view. The console log should help make it clear what the problem is too. There's no longer a view on the stack, so I'd assume the <Dynamic> component would just not render again, but what actually happens is it renders out of sync a bit, where the component renders again but the props are undefined during the last render. This has led to a footgun where I have to be careful in a view to not do anything after popping that view, and have to be overly-careful with checking for undefined props in createEffect calls, since it could be called in this weird situation where <Dynamic> is rendering one last time with a defined view but not the props associated with it. Any help would be much appreciated!
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
8 Replies
bigmistqke
bigmistqkeβ€’5mo ago
not sure I completely understand the problem, but I think maybe show's callback-mode could be the solution: https://playground.solidjs.com/anonymous/8fed05fb-56f9-4537-9d24-822d0077ae16
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
marcusbuffett
marcusbuffettβ€’5mo ago
yeah I went down a similar route, that solves the undefined props problem, but leaves another problem (which is present with the non-Show approach too), where when you add a second view, the first view gets called with the new view's props one time so it is strictly better I guess, but yeah still not in lock-step with the store one sec I'll push up a playground that highlights that with a slightly more realistic example
marcusbuffett
marcusbuffettβ€’5mo ago
Ah okay so here's the difference. If there's no view below the current view, the Show callback approach works fine, but when there's a view below, there's the same issue: https://playground.solidjs.com/anonymous/3928f3ef-8155-4e14-beb0-16ed515a916b
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
marcusbuffett
marcusbuffettβ€’5mo ago
so add a couple views, then hit "remove myself", and the console log will show the same issue
bigmistqke
bigmistqkeβ€’5mo ago
Solid Playground
Quickly discover what the solid compiler will generate from your JSX template
marcusbuffett
marcusbuffettβ€’5mo ago
niceee, yeah that seems like the ticket looked up the docs about what's happening with keyed too, seems like exactly what I need ty πŸ™
bigmistqke
bigmistqkeβ€’5mo ago
ur welcome! think one of those very few occasions where keyed actually is useful
marcusbuffett
marcusbuffettβ€’5mo ago
Just tested on my site, works perfectly afaict πŸŽ‰ been a pain point and source of weird bugs for a long time, thank you
Want results from more Discord servers?
Add your server
More Posts
Use solid as middlewareGoal: parse existing html from third party server, read all data-component attributes from HTML, loaHow to trigger createEffect when navigating to the same URL ?Hi, is it possible to trigger a createEffect that listens to location.search from the solid router'sGetting ReferenceError: React is not defined with Vitest + Solid Testing LibraryI honestly have no idea how I am receiving this error but I am despite testing using `@solidjs/testibackend solidstart or another backend.Does solidstart make sense if a third-party backend (fastapi) is used? I don't want to write backendUnderstanding the deployment of a SolidJS app (with a separate backend)I hope this doesn’t go too off topic because this is more of a general question but I am trying to uCreating custom SolidJS hook that can be used in a global scopeNeed some help understanding how to build a custom SolidJS hook that can be used both locally insideHow to set a cookie that is returned from api call?I'm using createAsync for a server api call. The api returns data with cookie that I need later. ```renderToString not workI have two questions about SSR: 1. It cannot work according to document about renderToString. The bruseNavigate wrapped in <Router>Hello! I'm trying to use useNavigate inside a top-level element so I can setup some event listeners Response.clone: Body has already been consumed. Seroval/trpc conflict?There was some discussion about this recently, but was there a way to fix this currently in user cod