feat: ensure behaviors connected prior to template rendering#6471
Conversation
📊 Tachometer Benchmark ResultsSummaryclickTrigger10x
create10k
createDelete5x
runFile1k
update10th
usedJSHeapSize
Resultsobservable-runFile1k
runFile1k
usedJSHeapSize
render-create10k
create10k
usedJSHeapSize
render-createDelete5x
createDelete5x
usedJSHeapSize
render-update10th
update10th
usedJSHeapSize
repeat-basic-splice-itemCount=1000&deleteCount=20&addCount=20
clickTrigger10x
usedJSHeapSize
repeat-nested-push-itemCount=100&addCount=20
clickTrigger10x
usedJSHeapSize
repeat-nested-reverse-itemCount=100
clickTrigger10x
usedJSHeapSize
repeat-nested-shift-itemCount=100
clickTrigger10x
usedJSHeapSize
repeat-nested-unshift-itemCount=100&addCount=20
clickTrigger10x
usedJSHeapSize
|
| if (this.needsInitialization) { | ||
| this.finishInitialization(); | ||
| } else if (this.view !== null) { | ||
| this.view.bind(this.source); |
There was a problem hiding this comment.
For the previous issue, is it because this.view.bind(this.source) is called before key.connectedCallback && key.connectedCallback(this);? Silly question: is it possible this.needsInitialization is false, but this.boundObservables !== null?
There was a problem hiding this comment.
Sorry, which previous issue?
No, that case is not possible. Both of those conditions can only be true before / during the first connection of the controller. However, it is possible that boundObservables is null while needsInitialization is true.
There was a problem hiding this comment.
Sorry, I mean the "current issue". I got the answer now, thx :)
…ior-to-template-rendering
…ior-to-template-rendering
EisenbergEffect
left a comment
There was a problem hiding this comment.
Looks good. Glad we reverted the isConnected change. I had a feeling that was going to break some things.
* feature and tests * Change files * Set isConnected at end of connect call to preserve existing behavior Co-authored-by: nicholasrice <nicholasrice@users.noreply.github.com>
Pull Request
📖 Description
This PR adjusts
ElementController.connect()to change the order in which behaviors are rendered relative to the element template. Behaviors should be connected before templates are rendered so that they're able to support setting context for child / shadowed elements.I've also moved where theElementControllersetsisConnectedto before behaviors are connected.This was done so that behaviors can add other behaviors and have them be connected immediately.I reverted this change because it broke component expectations and it turns out that since we use a Map to store behaviors, the itterable keys update when behaviors add other behaviors, giving the desired behavior w/o moving thesetIsConnected()call.🎫 Issues
#6462
👩💻 Reviewer Notes
I wasn't exactly sure when the Controller should setisConnectedduring connection and disconnection. I don't want to over-complicate that property, but I did consider expanding it to be'connected','disconnected','connecting','disconnecting'to remove ambiguity on which state it is in.📑 Test Plan
✅ Checklist
General
$ yarn changeComponent-specific
⏭ Next Steps