Updates to observables in `firstUpdated` not working
See original GitHub issueI haven’t had a chance to dig into this too much, but I’m noticing that setting an observable that the render method uses in firstUpdated doesn’t trigger a rerender. Setting a LitElement property does, as expected. Here’s a simple example of what I mean:
// Doesn't work - render isn't called again
class Component extends MobxLitElement {
@observable test = 1;
firstUpdated() {
this.test = 2;
}
render() {
return html`<h1>${this.test}</h1>`;
}
}
// Works as expected
class Component extends MobxLitElement {
@property({type: Number}) test = 1;
firstUpdated() {
this.test = 2;
}
render() {
return html`<h1>${this.test}</h1>`;
}
}
I’ll try poking around in the source a bit more to learn a bit about what’s going on under the hood, but I wanted to open the issue first.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:9
Top Results From Across the Web
Lifecycle - Lit.dev
LitElement-based components update asynchronously in response to observed property ... Implement firstUpdated to perform one-time work after the element's ...
Read more >Lifecycle - lit-element - Read the Docs
Manage property changes and updates for object subproperties. Mutations (changes to object subproperties and array items) are not observable. Instead, either ...
Read more >Angular observable not updating automatically - Stack Overflow
I need it to display the state and update when the state of analysisStatus changes. analysisStatus is being set like this: analysisStatus =...
Read more >Lifecycle - LitElement
Manage property changes and updates for object subproperties. Mutations (changes to object subproperties and array items) are not observable. Instead, either ...
Read more >LitElement Lifecycle 2 - codersnack.com
Implement firstUpdated to perform one-time work after the element's template has been created. Example: Focus an input element on first update.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Amazing! Thanks so much, might be the fastest fix I’ve ever seen!
@cannoneyed this fix has been published under
0.0.4.