when changing a dynamic variable that contains json <For> will not be re-rendered
I have a variable createsignal and it contains json and during actions on the page it receives data from the server and through the <For> element it should be displayed every time the variable is changed but it doesn't work what to do?
111 Replies
do you have any example code
html part or js?
which ever code is related to your problem
There's mostly js in there but it's very huge and complex
then a repro would be great
i can explain how it works
I'm not sure an explanation would be helpful here.
A repro helps demonstrate the issue better
Our JS code produces JSON like this:
And when our code adds more posts to the posts list, or adds other users to JSON (example below), the For list is not re-rendered.
And here's the For code:
And there are no problems in the js code that generates the json
How are you updating
props.users
?What do you mean?
like how are you updating it's signal
in index.jsx I have
yes, how are you updating the users
usersJson = await axios.... //request to api
setUsers(usersJson);
That's not how it works.
You need to use
setUsers
to set a new value (object) which is referentially different from the old value.that's what we do.
try setting
{equals: false}
option on the signal
this doesn't working
hmmm
And what is under the
<For>
What are you displaying with the data?swiper
slider
Could you show a little bit of the code?
Okay, and nothing is updated in the For?
Is the Swiper component from a library?
yes
Which library?
Swiper
Swiper - The Most Modern Mobile Touch Slider
Swiper is the most modern free mobile touch slider with hardware accelerated transitions and amazing native behavior.
Where does it list Swiper SolidJS? Found it Their landing page doesn't show it.
?
I don't see any exact issues with the code for the
For
, could be something else 🤔
If you console log in an effect, do you get the updated data?
createeffect is not called
so the data might not be getting updated
Especially if you're using
{equals: false}
and it's still not calling the createEffect
If I add an interval to the props.users() output, it will show that the data is being updated
right, but we want the effect to do that on it's own. I think reactivity is being broken somewhere
To me that would suggest that you are modifying the object but are not calling
setUsers
again.yeah that could be a possibility. Show a bit of the code of the axios request and calling
setUsers
does the <Users/>
component destructure props (although it shouldn't matter here) or is using mergeProps?i dont understand
im just using props
okay
I don't see any exact issues with your code. Could you show the code where you are calling
setUsers
I actually see no issues 🤣 @lxsmnsyc 🤖 Do you see anything wrong here?
and it doesn't even work with
{equals: false}
? That's so weird.When we put this option, the code starts replaying a billion times or just breaks SwiperJS
wait, that might be a good thing
that means the signal is updating and the swiper is being updated
There might be a loop somewhere causing it to keep replaying
or
first code breaks swiperjs
Do you get an error?
second code repeats billion times
no
okay, what happens when it breaks?
this swiper error
like
I see
when somewhere is variable broken
but without {equals: true} swiper working
or something else
this is okay, we can solve the problem from here
or you could try using a store actually
we just started porting the code over from next.js and it worked fine there
do you call this
start
inside createEffect
?yes
that then causes infinite loop
start(); called one time
yes, but reactivity tracks the
checkedUsers()
and then in the same place you do setCheckedUsers()
then because you call setCheckedUsers()
, any effect with checkedUsers()
has to rerun
there's untrack
you wrap anything you don't want function to react inside it
Also there's createResource
check it out here https://docs.solidjs.com/reference/basic-reactivity/create-resource ?
i added untrack
yeah so that probably still doesn't work
because you want
start
to be called when checkedUsers
change?no, when the page starts(1 time)
no
only 1 time
oh ok
I don't think there's a infinite loop,
So does it work now however you wanted?
Before the addition of untrack there was an infinite loop
oh okay
no(
What doesn't work
The problem described in the topic description is still active
rendering a posts
with {equals: false} & untrack, do you still make request for new data?
yes
is there another place in code that this request is made?
yes
Near where the signal is created
In the component
That should give you an idea whether they behave the same or reactivity is broken in between.
?
allUsersIdStatic
& usersJson
are keys of object & the object. Then you update usersJson
by what request returned for all it's keys (allUsersIdStatic
), that should not give usersJson
any new values. Are you sure that this request gives you different data?I'm sure this query returns different data
Is this when the
usersResponseToAdd
code runs?oh sorry
no
if inserted directly into the function after the usersResponse line, it will not work
I'm asking whether the output was from running the
start
section of the code or from running the usersResponseToAdd
section of the code.I made a mistake in that screenshot and put the code in the wrong place.
no
I'd try replacing whole
onUserSwipe
body with { setUsers({}) }
, does swiper then disappears?yes
now leave
setUsers({})
at the beggining of the function, and paste previous body after it
does it works then?
it shouldn'tno
ok start from original body again, now before
setUsers(usersJson);
, do setUsers({})
it works
but
reloading realoding swiper
do you still have
{equals: false}
?yes
what do you mean reloading reloading swiper? infinite loop?
I misspelled
it's just that when he uploads new posts, the swiper reboots, so to speak.
I can only now think that this swiper somehow isn't reactive to children
can you try doing same things in jsx, the
<For>
and some text inside, all without swiper?
and without setUsers({})
It's complicated because it's all tied to him.
there's ids and a bunch of other things
I want to know just something like that:
if that works WITHOUT
setUsers({})
, and WITH {equals: false}
, just thow it somewhere next to swiperdoesn't work
without setusers
hmm
I misspelled there, should be
Object.keys(props.users().success)
, but if it compiled, you probably did it rightnothing
wait
output
what's this output of?
can you elaborate more? in devTools you see something that page doesn't display?
no
and another problem
setUsers() reactivity trigger doesn't working