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

Update html.go #767

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

gepengscu
Copy link

Allow rendering child component which is created outside Render() method.

Render child component which is created outside Render() method.
@oderwat
Copy link
Contributor

oderwat commented Aug 29, 2022

I tested this with our projects and did not find any problems. It does in fact fix misc variants of this problem. And I hope that it can be merged asap if @maxence-charriere does not see a problem with it!

@oderwat
Copy link
Contributor

oderwat commented Sep 5, 2022

@maxence-charriere would you be so nice as to give your opinion on this topic?

Copy link
Owner

@maxence-charriere maxence-charriere left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That loop within is hard to read/understand for me.

So it seems that:

  • for each child already mounted, it looks if b is already here
  • then if its the case, the found element is swapped with the current children
  • the component is not updated because it is itself

How does this solve the order problem? The node is switched on the Go side but I don't see anything done on the DOM side.

@oderwat
Copy link
Contributor

oderwat commented Sep 5, 2022

That loop within is hard to read/understand for me.

Phew, I thought it was just me :)

All I know is that this fixes the problem with this type of coding. Without "this" fix, Go-App is acting very strange, which is why I think this may qualify as a real bug, and there needs to be a resolution.

@maxence-charriere
Copy link
Owner

maxence-charriere commented Sep 5, 2022

I agree. I was thinking about this before releasing the latest version. I got some ideas. Just need to experiment a bit.

@gepengscu
Copy link
Author

gepengscu commented Sep 5, 2022

Let a= [b1,b2,b3,b4]
Delete b1
The Go side a is [b2,b3,b4]. Named a with a1.
Go-app side a is [b1,b2,b3]. Name a with a2.
a1.bi and a2.bi are same instance and have same memory address.
Html.updateWith sets a2.b1 with a1.b2, and a2.b2 with a1.b3, and a2.b3 with a1.b4.
This results the erroe that b3 has same value with b4.
The error is triggered because bi are same type and updateWith removes item from last always, and the deleted bi is not the last one of a.

@gepengscu
Copy link
Author

Issues #759 has a unit test.

@oderwat
Copy link
Contributor

oderwat commented Sep 5, 2022

@gepengscu That makes a lot of sense. Having ranges like that should probably introduce an invisible offset to aid in correctly updating the elements. I also do not like that mounting the same type over an existing one is just updating the nodes (my "mount point" problem). Probably one should be able to make components of the same type unique to force swaps instead of overwriting. Which feels like a similar yet other problem.

@gepengscu
Copy link
Author

gepengscu commented Sep 6, 2022

The key is that go-app changed fields value of ui object owend by Go side when update.That will be a problem when ui is not created in render method dynamicaly.

@oderwat
Copy link
Contributor

oderwat commented Oct 27, 2022

I agree. I was thinking about this before releasing the latest version. I got some ideas. Just need to experiment a bit.

Will there be any updates to this?

@gepengscu
Copy link
Author

I agree. I was thinking about this before releasing the latest version. I got some ideas. Just need to experiment a bit.

Will there be any updates to this?

@maxence-charriere Will there be any updates to this?

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

Successfully merging this pull request may close these issues.

3 participants