Tom
Tom
SSolidJS
Created by Tom on 10/27/2024 in #support
Reactivity stopped - advice for debugging?
Thanks for responding - just figured out it's not a Solid issue at all 🙈
3 replies
SSolidJS
Created by Tom on 10/27/2024 in #support
Reactivity stopped - advice for debugging?
Also worth mentioning - it's reacting to a global store, not local signals, and other parts of the UI remain reactive to the store.
3 replies
SSolidJS
Created by Tom on 10/15/2024 in #support
Context lost on HMR
Doesn't HMR re-execute all recursively included modules, even if they haven't changed?
27 replies
SSolidJS
Created by Tom on 10/15/2024 in #support
Context lost on HMR
It's tricky because my UI is fundamentally recursive (tree editor). I will look into dependency injection to resolve
27 replies
SSolidJS
Created by Tom on 10/15/2024 in #support
Context lost on HMR
I think I might still have issues with import cycles. I thought I could use dynamic imports to avoid them, but it looks like any kind of import cycle is a problem, not just static ones.
27 replies
SSolidJS
Created by Tom on 10/15/2024 in #support
Context lost on HMR
I've reverted back to my createHotStableContext now, but what I tried was a one-line module, just export const MyContext = createContext()
27 replies
SSolidJS
Created by Tom on 10/15/2024 in #support
Context lost on HMR
@lxsmnsyc 🤖 anything else I can try, given moving createContext to a .ts did not help?
27 replies
SSolidJS
Created by Tom on 10/15/2024 in #support
Context lost on HMR
Yes - I got rid of all those recently for exactly that reason
27 replies
SSolidJS
Created by Tom on 10/15/2024 in #support
Context lost on HMR
A console.log in the new file with createContext shows that the file is getting reloaded - not sure if that's expected or not
27 replies
SSolidJS
Created by Tom on 10/15/2024 in #support
Context lost on HMR
I tried moving the createContext into a different file (.ts) and I'm still losing state on hot reload
27 replies
SSolidJS
Created by Tom on 10/15/2024 in #support
Context lost on HMR
I do have the create and use in the same file - I'll try separating
27 replies
SSolidJS
Created by Tom on 10/15/2024 in #support
Context lost on HMR
Ohh sorry I scanned what you said too quickly
27 replies
SSolidJS
Created by Tom on 10/15/2024 in #support
Context lost on HMR
I'm not understanding how this helps, because vite follows the import chains and reloads those modules too. I already have it in a separate file.
27 replies
SSolidJS
Created by Tom on 10/15/2024 in #support
Context lost on HMR
I solved this (well, me and Claude 3.5 solved it). In case it's helpful to others, here's the solution (I which discord would publish these threads on the web so this stuff was more findable)
export function createHotStableContext<T>(name: string, defaultValue?: T): Context<T> {
const contextKey = `hot-context-${name}`

const {hot} = import.meta
if (hot) {
return hot.data[contextKey] ??= createContext<T>(defaultValue as T)
} else {
return createContext<T>(defaultValue as T)
}
}

export const MyContext = createHotStableContext<MyType>('MyContext')
export function createHotStableContext<T>(name: string, defaultValue?: T): Context<T> {
const contextKey = `hot-context-${name}`

const {hot} = import.meta
if (hot) {
return hot.data[contextKey] ??= createContext<T>(defaultValue as T)
} else {
return createContext<T>(defaultValue as T)
}
}

export const MyContext = createHotStableContext<MyType>('MyContext')
27 replies
SSolidJS
Created by Tom on 10/15/2024 in #support
Context lost on HMR
It's already in a different file but that file is getting reloaded when I make a change to a component file that (indirectly) imports it. I guess I need to understand more about how vite HMR decides which modules to reload.
27 replies