Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@sorvell
Copy link
Member

@sorvell sorvell commented Feb 27, 2025

Fixes #4860.

  • watch no longer triggers a reactive update on a SignalWatcher element
  • watch can be used without SignalWatcher
  • adds effect(callback, options) which runs the provided function whenever any signals it accesses are changed. If an options object is provided, the effect is coordinated with the given element and is called by default after rendering updates but can optionally include an options beforeUpdate: true to process the effect before any rendering updates.

@changeset-bot
Copy link

changeset-bot bot commented Feb 27, 2025

🦋 Changeset detected

Latest commit: 3613282

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@lit-labs/signals Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions
Copy link
Contributor

github-actions bot commented Feb 27, 2025

📊 Tachometer Benchmark Results

Summary

nop-update

  • this-change, tip-of-tree, previous-release: unsure 🔍 -10% - +5% (-1.24ms - +0.70ms)
    this-change vs tip-of-tree

render

  • this-change: 46.57ms - 58.47ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -5% - +2% (-1.06ms - +0.40ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -1% - +3% (-0.40ms - +0.97ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -4% - +2% (-4.35ms - +2.29ms)
    this-change vs tip-of-tree

update

  • this-change: 502.73ms - 510.18ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -7% - +2% (-2.91ms - +0.78ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -1% - +2% (-1.14ms - +1.74ms)
    this-change vs tip-of-tree
  • this-change, tip-of-tree, previous-release: unsure 🔍 -0% - +2% (-0.71ms - +9.79ms)
    this-change vs tip-of-tree

update-reflect

  • this-change: 486.70ms - 491.28ms
  • this-change, tip-of-tree, previous-release: unsure 🔍 -2% - +1% (-7.92ms - +6.38ms)
    this-change vs tip-of-tree

Results

this-change

render

VersionAvg timevs
46.57ms - 58.47ms-

update

VersionAvg timevs
502.73ms - 510.18ms-

update-reflect

VersionAvg timevs
486.70ms - 491.28ms-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
19.03ms - 20.01ms-unsure 🔍
-5% - +2%
-1.06ms - +0.40ms
unsure 🔍
-8% - +0%
-1.71ms - +0.11ms
tip-of-tree
tip-of-tree
19.32ms - 20.39msunsure 🔍
-2% - +5%
-0.40ms - +1.06ms
-unsure 🔍
-7% - +2%
-1.41ms - +0.47ms
previous-release
previous-release
19.55ms - 21.09msunsure 🔍
-1% - +9%
-0.11ms - +1.71ms
unsure 🔍
-2% - +7%
-0.47ms - +1.41ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
38.34ms - 41.33ms-unsure 🔍
-7% - +2%
-2.91ms - +0.78ms
unsure 🔍
-8% - +2%
-3.35ms - +0.91ms
tip-of-tree
tip-of-tree
39.82ms - 41.98msunsure 🔍
-2% - +7%
-0.78ms - +2.91ms
-unsure 🔍
-5% - +4%
-2.01ms - +1.70ms
previous-release
previous-release
39.54ms - 42.57msunsure 🔍
-2% - +8%
-0.91ms - +3.35ms
unsure 🔍
-4% - +5%
-1.70ms - +2.01ms
-

nop-update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
11.74ms - 12.93ms-unsure 🔍
-10% - +5%
-1.24ms - +0.70ms
faster ✔
1% - 14%
0.03ms - 1.93ms
tip-of-tree
tip-of-tree
11.83ms - 13.37msunsure 🔍
-6% - +10%
-0.70ms - +1.24ms
-unsure 🔍
-13% - +2%
-1.78ms - +0.35ms
previous-release
previous-release
12.57ms - 14.05msslower ❌
0% - 16%
0.03ms - 1.93ms
unsure 🔍
-3% - +14%
-0.35ms - +1.78ms
-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
35.78ms - 36.84ms-unsure 🔍
-1% - +3%
-0.40ms - +0.97ms
unsure 🔍
-1% - +3%
-0.38ms - +0.97ms
tip-of-tree
tip-of-tree
35.59ms - 36.47msunsure 🔍
-3% - +1%
-0.97ms - +0.40ms
-unsure 🔍
-2% - +2%
-0.60ms - +0.62ms
previous-release
previous-release
35.60ms - 36.43msunsure 🔍
-3% - +1%
-0.97ms - +0.38ms
unsure 🔍
-2% - +2%
-0.62ms - +0.60ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
77.34ms - 79.24ms-unsure 🔍
-1% - +2%
-1.14ms - +1.74ms
unsure 🔍
-2% - +2%
-1.55ms - +1.42ms
tip-of-tree
tip-of-tree
76.92ms - 79.07msunsure 🔍
-2% - +1%
-1.74ms - +1.14ms
-unsure 🔍
-2% - +2%
-1.93ms - +1.20ms
previous-release
previous-release
77.22ms - 79.50msunsure 🔍
-2% - +2%
-1.42ms - +1.55ms
unsure 🔍
-2% - +2%
-1.20ms - +1.93ms
-
this-change, tip-of-tree, previous-release

render

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
104.90ms - 111.23ms-unsure 🔍
-4% - +2%
-4.35ms - +2.29ms
unsure 🔍
-5% - +1%
-5.52ms - +1.10ms
tip-of-tree
tip-of-tree
108.10ms - 110.09msunsure 🔍
-2% - +4%
-2.29ms - +4.35ms
-unsure 🔍
-2% - +0%
-2.57ms - +0.22ms
previous-release
previous-release
109.29ms - 111.24msunsure 🔍
-1% - +5%
-1.10ms - +5.52ms
unsure 🔍
-0% - +2%
-0.22ms - +2.57ms
-

update

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
511.22ms - 518.17ms-unsure 🔍
-0% - +2%
-0.71ms - +9.79ms
unsure 🔍
-1% - +1%
-5.99ms - +4.84ms
tip-of-tree
tip-of-tree
506.23ms - 514.09msunsure 🔍
-2% - +0%
-9.79ms - +0.71ms
-unsure 🔍
-2% - +0%
-10.83ms - +0.61ms
previous-release
previous-release
511.11ms - 519.42msunsure 🔍
-1% - +1%
-4.84ms - +5.99ms
unsure 🔍
-0% - +2%
-0.61ms - +10.83ms
-

update-reflect

VersionAvg timevs this-change
vs tip-of-tree
tip-of-tree
vs previous-release
previous-release
this-change
517.73ms - 526.16ms-unsure 🔍
-2% - +1%
-7.92ms - +6.38ms
unsure 🔍
-1% - +1%
-3.85ms - +6.30ms
tip-of-tree
tip-of-tree
516.94ms - 528.49msunsure 🔍
-1% - +2%
-6.38ms - +7.92ms
-unsure 🔍
-1% - +2%
-4.44ms - +8.42ms
previous-release
previous-release
517.89ms - 523.55msunsure 🔍
-1% - +1%
-6.30ms - +3.85ms
unsure 🔍
-2% - +1%
-8.42ms - +4.44ms
-

tachometer-reporter-action v2 for Benchmarks

@github-actions
Copy link
Contributor

The size of lit-html.js and lit-core.min.js are as expected.

@sorvell sorvell marked this pull request as ready for review March 11, 2025 23:35
@sorvell sorvell requested a review from kevinpschaaf as a code owner March 11, 2025 23:35
@sorvell sorvell changed the title watch no longer triggers update; adds SignalWatcher.effect watch no longer triggers update; adds effect Mar 13, 2025
@justinfagnani justinfagnani changed the title watch no longer triggers update; adds effect [labs/signals] watchI() no longer triggers update; adds effect Mar 13, 2025
@justinfagnani justinfagnani changed the title [labs/signals] watchI() no longer triggers update; adds effect [labs/signals] watch() no longer triggers update; adds effect Jul 17, 2025
}

export interface ElementEffectOptions extends EffectOptions {
element?: SignalWatcher & SignalWatcherApi;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JSDocs here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, no longer needed.

@sorvell sorvell requested a review from justinfagnani July 17, 2025 21:05
manualDispose?: boolean;
}

export interface ElementEffectOptions extends EffectOptions {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this interface used anywhere?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed, no longer needed.

Copy link
Collaborator

@justinfagnani justinfagnani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome!

Two small comments left

@Westbrook
Copy link
Contributor

Getting into some finer testing of this change as we await it landing and wondered which of these is "correct".

In https://lit.dev/playground/#gist=5cfb3e893dbc5412ed1468483be5fa80 we get the render lifecycle on all three buttons, but only the Signal bindings on the first and last (signal powered) element.

In https://lit.dev/playground/#gist=3b14cb4a58de364ec7686f230a88435d we do not get the render lifecycle in either of the Signal bindings.

Maybe there's changes in this PR before I lifted the code, but wanted to confirm as we're working out how we want to consumer these capabilities in my team right now.

@sorvell
Copy link
Member Author

sorvell commented Nov 4, 2025

Forwarded from discord

  • This should be removed: https://lit.dev/docs/data/signals/#:~:text=For%20coordination%20purposes,template%20are%20skipped
  • We changed this since signals are not part of the element's reactive properties so if they triggered an update it would be an update without any visible changes to properties.
  • We've added updateEffect which lets you use signal values when signals change. This method is coordinated with the rendering impact that any of those signals have on the element and can be either before or after them, based on options e.g. updateEffect(() => console.log(mySIgnal.get()), {beforeUpdate: true})

Steve Orvell added 2 commits November 6, 2025 17:17
@sorvell sorvell merged commit 5ee7c1f into main Nov 7, 2025
10 checks passed
@sorvell sorvell deleted the signals-watch-wo-update branch November 7, 2025 12:57
@lit-robot lit-robot mentioned this pull request Dec 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[labs/signals] watch prevents re-render when an unrelated signal changes

3 participants