createEffect is reactive, JSX isn't

export const SavedLineView = (props: { loading: Accessor<boolean> }) => {
createEffect(() => {
// This gets called with true, then false, the expected behavior
console.log("What's the value here?", props.loading());
});
return (
<Show
// This doesn't update, it's always true (the initial value)
when={props.loading()}
fallback={
<div class="row w-full justify-center pt-12">
<Puff color={c.primaries[65]} />
</div>
}
>
<SidebarTemplate header={"Moves saved!"} bodyPadding actions={[]} />
</Show>
);
};
export const SavedLineView = (props: { loading: Accessor<boolean> }) => {
createEffect(() => {
// This gets called with true, then false, the expected behavior
console.log("What's the value here?", props.loading());
});
return (
<Show
// This doesn't update, it's always true (the initial value)
when={props.loading()}
fallback={
<div class="row w-full justify-center pt-12">
<Puff color={c.primaries[65]} />
</div>
}
>
<SidebarTemplate header={"Moves saved!"} bodyPadding actions={[]} />
</Show>
);
};
I have this code, where I'm accessing props.loading (which is an accessor created from createSignal), and then also accessing it in the JSX via Show. The createEffect reacts properly to the signal being updated, the JSX does not. I'm doing some weird stuff where the signal is created in response to a click, so it's maybe created with a different owner or something, but I didn't think it would matter the owner/tracking context when the signal is created, only when it's accessed. I basically thought that createEffect should be doing a very similar thing to <Show when={x()}/>, so I'm confused why one works and one doesn't. Hoping for an idea of how components "get" reactivity, so that I could understand an issue like this from first principles
4 Replies
marcusbuffett
marcusbuffettOP9mo ago
This component is rendered from a <Dynamic>, would that make it lose reactivity somehow? I'm seeing that in the code for Dynamic, the component is rendered inside an untrack() call? https://github.com/solidjs/solid/blob/dbdc27df2246ec05c0e32cf7b461ddbe4223915f/packages/solid/web/src/index.ts#L132
apollo79
apollo799mo ago
No, the Dynamic shouldn't affect this, just as the createEffect, the template is still reactive You usually don't pass accessors as props though, but call it as you pass it and solid transforms it into a getter, so that could be the reason here. Try passing loading={loading()} and then consume it as boolean in your component
bigmistqke
bigmistqke9mo ago
can u make a minimal reproduction of it in the playground.solidjs.com?
Otonashi
Otonashi9mo ago
this sounds like somewhere in a parent component you're accessing the result of Show in a non-reactive manner though honestly that's pretty difficult to do so it could be something else
Want results from more Discord servers?
Add your server