Skip to content

Commit

Permalink
Merge pull request #620 from preactjs/fix/1-3-0-simplify-text-updates
Browse files Browse the repository at this point in the history
simplify text update patch
  • Loading branch information
developit authored Nov 19, 2024
2 parents 5715c4c + 4cda002 commit ade7302
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 14 deletions.
5 changes: 5 additions & 0 deletions .changeset/selfish-ravens-sit.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@preact/signals": patch
---

Simplify text update patch to avoid using new internals
20 changes: 6 additions & 14 deletions packages/preact/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,16 @@ function SignalValue(this: AugmentedComponent, { data }: { data: Signal }) {
}

this._updater!._callback = () => {
// When overriding Effect._callback, source versions are only updated between _start() and end(), not when the callback is executed.
// To fix this, whenever _callback is executed we update the Effect's source versions to their latest values.
// Note that we don't do this for the re-rendering Component updater, because that eventually calls _start().
for (
let source = this._updater!._sources;
source !== undefined;
source = (source as any)._nextSource
) {
(source as any)._version = (source as any)._source._version;
}
const end = this._updater!._start();
const value = s.value;
end();

if (isValidElement(s.peek()) || this.base?.nodeType !== 3) {
if (isValidElement(value) || this.base?.nodeType !== 3) {
this._updateFlags |= HAS_PENDING_UPDATE;
this.setState({});
return;
} else {
(this.base as Text).data = value;
}

(this.base as Text).data = s.peek();
};

return computed(() => {
Expand Down

0 comments on commit ade7302

Please sign in to comment.