question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Updates to observables in `firstUpdated` not working

See original GitHub issue

I 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

1reaction
cannoneyedcommented, Apr 24, 2020

Amazing! Thanks so much, might be the fastest fix I’ve ever seen!

0reactions
benjamindcommented, Apr 24, 2020

@cannoneyed this fix has been published under 0.0.4.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found