Skip to content

simplify text update patch #620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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