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

virtual component uses part to associate with container #42

Open
askbeka opened this issue Dec 14, 2018 · 7 comments
Open

virtual component uses part to associate with container #42

askbeka opened this issue Dec 14, 2018 · 7 comments
Labels
bug Something isn't working virtual Virtual components

Comments

@askbeka
Copy link
Contributor

askbeka commented Dec 14, 2018

Since, container for virtual component is mapped to part in cache, same container is reused for other component:

html`${<p>${predicate ? ComponentOne() : ComponentTwo()}</p>}`

I made demo reproducing the issue

I haven't done deep dive into solving it, but from first sight container can be mapped to renderer instead of part

@matthewp matthewp added the bug Something isn't working label Dec 14, 2018
@matthewp
Copy link
Owner

Ah, yeah this is a bit of a problem isn't it. We might need a 2-dimensional map (the part maps to another map which contains renderer => container mapping). However I'm not quite sure this would work either because the renderer function might be defined within another renderer. This case:

function App() {
  return html`<p>${virtual(() => html`hello world`)}</p>`;
}

So... I'm not sure what to do about this exactly. Will ponder on it some more...

@dredzone
Copy link

@matthewp first, thanks for a great library. Any resolution on this bug or thoughts what is the good solution may be?

@matthewp
Copy link
Owner

I haven't thought of a solution yet. I don't use virtual components a whole lot to be honest, maybe someone who uses them more will have a good idea for this...

@askbeka
Copy link
Contributor Author

askbeka commented Feb 15, 2019

I have gave it a thought and tried out couple of ideas, but there is something about how lit-html directives work that does not allow having virtual components, and I propose to ditch it for now.

But there is an alternative of course, that is already in place
(seems haunted has a bug. it does not update on setState.)

Only difference of course is that those are not really "Components" since they do not have scheduling and etc.
But code reuse is the same, and there will be no issues we have with directives.

They are more like composed hook but one that also returns a template

@askbeka
Copy link
Contributor Author

askbeka commented Feb 15, 2019

I prose to ditch virtual part and document better how you can use above described method.
With that method you have to have "Real" component defined somewhere up in the tree.
Which might be also a good practice, since you want to isolate your app from outside. But not maybe use Real components everywhere, you can just use a function to separate out your code

@matthewp
Copy link
Owner

I think ditching virtual components would be a drastic measure, people really like that part of Haunted. If this is the only problem I don't think that's enough to say we can't make it work. I'll try to free up some time to take a closer look into this issue myself.

@matthewp matthewp added the virtual Virtual components label Mar 1, 2019
@matthewp
Copy link
Owner

matthewp commented Mar 1, 2019

I fixed #69 so I have my brain wrapped around virtual components a little more than I had. So I might take a look at this issue soonish and see if I can come up with a solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working virtual Virtual components
Projects
None yet
Development

No branches or pull requests

3 participants