Skip to content
This repository has been archived by the owner on Sep 19, 2021. It is now read-only.

Nested StatefulWidgets working? #9

Open
brianegan opened this issue Aug 30, 2018 · 4 comments
Open

Nested StatefulWidgets working? #9

brianegan opened this issue Aug 30, 2018 · 4 comments

Comments

@brianegan
Copy link

Hey hey :) Really cool work!

I saw you'd added StatefulWidgets and decided to take this lib for a spin! I made this following sample app: https://github.com/brianegan/github_search_angular_flutter/tree/master/mariposa_app

I ran into one funny issue:

  1. Create a StatefulWidget called GithubApp
  2. Nest a StreamBuilder Widget inside (another StatefulWidget I ported from Flutter)
  3. StreamBuilder's createState is never called, subscription never established

Solution: Convert GithubApp into a function. StatefulWidget's createState function is called correctly.

@thosakwe
Copy link
Collaborator

Thanks for pointing this out. I'm thinking that this is probably an error in my implementation of StatefulWidgets, which holds a Map from instances of StatefulWidget to instances of State.

This can be changed, because Widget classes can potentially be instantiated every time a render is called.

What I'll probably do instead of using the Widget instance itself is storing the data-mariposa-stamp (I forgot the actual name) in the map, and using that instead.

But what I really will do is peek at the implementation of StatefulWidget in Flutter, as a Map-based solution doesn't seem to be the right way.

@thosakwe
Copy link
Collaborator

I think that the root of this is the way that mariposa.render currently works.

As it is, the root element is instantiated once, and rendered against, but on subsequent re-renders, child nodes are inevitably re-instantiated.

A smarter solution would be for Mariposa to keep track of the rendered tree (which is just Nodes, and no Widgets), and based on that perform reconciliation.

@brianegan
Copy link
Author

brianegan commented Aug 31, 2018

Ah, that might make sense. I saw some weird stuff happening WRT rendering in general. Sometimes the Div would be replaced properly, other times it wouldn't. I'll try to create a minimal test case

@thosakwe
Copy link
Collaborator

Thanks, appreciate it. The current renderer is something of a hack, but with some love it can work well, and be unit tested.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants