-
Notifications
You must be signed in to change notification settings - Fork 14
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
Table doesn't always refresh when value of data
prop is changed
#17
Comments
@msaraiva This is preventing us from upgrading surface. This is a horrid bug that needs to be fixed ASAP. I can't use tables on Surface 0.5.0+ because of this bug. |
@SophisticaSean, why does this prevent you from upgrading Surface? |
I didn't manage to reproduce this issue. Could you provide an example? |
This is the code I wrote: defmodule SurfaceTestWeb.UserLive.Index do
use Surface.LiveView
alias SurfaceBulma.Table
data users, :list
@impl true
def mount(_params, _session, socket) do
Process.send_after(self(), :duplicate_users, 1000)
{:ok, assign(socket, :users, [%{name: "John", age: 9}])}
end
@impl true
def render(assigns) do
~F"""
<h1>Listing Users</h1>
<Table data={user <- @users} id="1">
<Table.Column label="name">{ user.name }</Table.Column>
<Table.Column label="age">{ user.age }</Table.Column>
</Table>
"""
end
@impl true
def handle_info(:duplicate_users, socket) do
duplicated =
socket.assigns.users
|> List.duplicate(2)
|> List.flatten()
Process.send_after(self(), :duplicate_users, 1000)
{:noreply, assign(socket, users: duplicated)}
end
end I'm running master. |
The bug only occurs when the data has already been sorted. I was looking at a fix just now and figured that an internal flag that represents whether the data has been updated would maybe do the trick. |
@hadfieldn, @SophisticaSean I think the bug is fixed in master now, could you please confirm? |
@Zurga I'll look today, thanks for looking at this so quickly. We use like 20 different instances of Bulma.Table and we have some pretty complicated tables. If master doesn't fix this I'll get a demo app to reproduce. The architecture is as follows: Parent component Users has child live component of UserReporting table which is the table in question. On Surface 0.3+ and likewise with Bulma the UserReporting table doesn't change when the underlying data in the assigns changes, properly. What's most odd about this is I can get some of the fields in the table to change. I experimented by adding a boolean column to the table, and the boolean value is derived from an arbitrary drop down menu in the UserReporting component. When that drop down changes the table updates only that column even if the rest of the table data has changed. On Surface 0.2.1 and Bulma 0.1.0 the tables update correctly when the underlying data changes. |
@Zurga I have confirmed this bug is now fixed in master, could you cut a release pretty please? :) |
also, thanks so much for the quick fix! :) |
@SophisticaSean, you are welcome, it has been released. |
@Zurga do you guys have an open list of things you'd like done? I wouldn't mind tossing some time your way! |
@SophisticaSean, thanks that would be really nice! I created an issue with a wishlist: #23 |
When the
data
prop ofSurfaceBelma.Table
is changed, if the internalsorted_by
assign is nil, thensorted_data/1
returns the newdata
value only if thesorted_data
assign is nil, which is true only on mount.As a result, the table does not render changes made to the
data
prop until it is remounted or resorted.(As a workaround, I was able to force a refresh by calling
send_update/3
to trigger an update, passingsorted_data
as an assign set to the updated value ofdata
, so that it would be the value returned bysorted_data/1
.)If I can find the time in the next few days I'll try to submit a fix, but I wanted to get this recorded before I forget.
The text was updated successfully, but these errors were encountered: