-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using the model ID as a nested key is inconsistent #2179
Comments
@redbastie that is a morphdom issue. Below is an explaination I use for morphdom issues. I'd recommend in your instance using something like key('vehicle' . $vehicle->id)
Hope this helps! |
it also happen to me.
Even i use 'user'.$user->id as key, it still not refreshing the data There are two ways to resolve this issue (hacky way)
then it can update the username, but other columns not. Is it expected? |
@hilmanski I have seen some issues where $refresh in a listener doesn't work properly. Try making a method which has refresh in that and call that from the listener instead and see if it runs ok. |
Thanks @joshhanley for the reply. I also didn't find documentation for $refresh on livewire's site. Do you know why/where? *I think, it's good to let this issue open, so we aware there's still this dom issue which is important for livewire future. [update] |
@hilmanski yeah it's an issue, but it's not an issue, in the sense that morphdom needs things to be setup in a specific way (see my first comment) otherwise it breaks. If setup right though, works perfectly fine 😆 Yeah I meant the first option, $refresh in a method, but that may not work anyway if there is morphdom issues. Can you share your code, so we can see if we can get it running? |
@joshhanley I am emitting an update event from a child component up to the parent list component. Trying to refresh the list. Using this:
the list is not refreshing. However using
does refresh the list. My original post from the forum: https://forum.laravel-livewire.com/t/view-is-not-refreshing-when-the-collection-is-updated/3312/8 |
@artjomzab Livewire won't refresh child components as they are isolated from each other, so the way to get them to refresh is a bit of a hack, using keys. What happens is by changing the key, Livewire thinks it's actually a new dom element and so it deletes the old child component and launches a new one with the new key, and as such the new, refreshed, data. Using the key like I suggested I would consider this a bad idea, purely because time changes every time the parent component re-renders. As such all child components that have that in the key will be deleted and replaced, and any dirty state they may have contained will be gone. What I prefer to do now, is actually create a property on the parent component like Then on your child components, set the key to something like this The last step then, is whenever you need to refresh all of the children (like in a listener), in the parent component you would just generate a new key in your method using Doing it this way prevents all components having to be re-initialised every time on the front end, but gives you the option to force changes when needed. Hope this helps! |
I just use uniqid() for keys now. Works great. |
It's a good strategy. Thanks @joshhanley. |
@quanengineering no worries! @redbastie I'm going to close this now. Feel free to reopen if you think your question isn't fully answered 🙂 |
👋 Oh Hi! I'm Squishy, the friendly jellyfish that manages Livewire issues. I see this issue has been closed. Here in the Livewire repo, we have an "issues can be closed guilt-free and without explanation" policy. If for ANY reason you think this issue hasn't been resolved, PLEASE feel empowered to re-open it. Re-opening actually helps us track which issues are a priority. Reply "REOPEN" to this comment and we'll happily re-open it for you! (More info on this philosophy here: https://twitter.com/calebporzio/status/1321864801295978497) |
When I use this in a nested component:
It is quite buggy. Sometimes the component won't refresh, or will outright throw a
TracksRenderedChildren
error.However, if I use this instead:
Everything works flawlessly. Can someone explain?
The text was updated successfully, but these errors were encountered: