Skip to content
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

Closed
hadfieldn opened this issue May 12, 2021 · 12 comments
Closed

Table doesn't always refresh when value of data prop is changed #17

hadfieldn opened this issue May 12, 2021 · 12 comments

Comments

@hadfieldn
Copy link

When the data prop of SurfaceBelma.Table is changed, if the internal sorted_by assign is nil, then sorted_data/1 returns the new data value only if the sorted_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, passing sorted_data as an assign set to the updated value of data, so that it would be the value returned by sorted_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.

@SophisticaSean
Copy link

@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.

@Zurga
Copy link
Collaborator

Zurga commented Aug 4, 2021

@SophisticaSean, why does this prevent you from upgrading Surface?

@v0idpwn
Copy link

v0idpwn commented Aug 4, 2021

I didn't manage to reproduce this issue. Could you provide an example?

@v0idpwn
Copy link

v0idpwn commented Aug 4, 2021

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.

@Zurga
Copy link
Collaborator

Zurga commented Aug 4, 2021

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.

@Zurga
Copy link
Collaborator

Zurga commented Aug 4, 2021

@hadfieldn, @SophisticaSean I think the bug is fixed in master now, could you please confirm?

@SophisticaSean
Copy link

SophisticaSean commented Aug 4, 2021

@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.

@SophisticaSean
Copy link

@Zurga I have confirmed this bug is now fixed in master, could you cut a release pretty please? :)

@SophisticaSean
Copy link

also, thanks so much for the quick fix! :)

@Zurga
Copy link
Collaborator

Zurga commented Aug 5, 2021

@SophisticaSean, you are welcome, it has been released.
If you find time to contribute to SurfaceBulma it would be appreciated :)

@SophisticaSean
Copy link

@Zurga do you guys have an open list of things you'd like done? I wouldn't mind tossing some time your way!

@Zurga
Copy link
Collaborator

Zurga commented Aug 5, 2021

@SophisticaSean, thanks that would be really nice! I created an issue with a wishlist: #23

@Zurga Zurga closed this as completed Aug 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants