Skip to content

Batch updates in flushSync - #5173

Merged
JoviDeCroock merged 1 commit into
v10.xfrom
flush-sync-batch
Jul 30, 2026
Merged

Batch updates in flushSync#5173
JoviDeCroock merged 1 commit into
v10.xfrom
flush-sync-batch

Conversation

@JoviDeCroock

Copy link
Copy Markdown
Member

Summary

Make preact/compat’s flushSync batch updates performed inside its callback.

Previously, flushSync temporarily configured options.debounceRendering to execute every scheduled render immediately. This made updates synchronous, but it also caused each state setter to render independently:

flushSync(() => {
	setA(1);
	setB(1);
});

The example above could render twice instead of batching both updates into one synchronous commit.

This change captures the scheduled render callback while the user callback runs, then flushes it once before returning. The previous debounce function is restored in a finally block.

Results

Measured with Octane’s nested update benchmark:

Operation Before After Change
Batched sweep, ancestor-first 0.322 ms 0.081 ms −75%
Batched sweep, descendant-first 0.301 ms 0.079 ms −74%
Suite geomean 0.161 ms 0.116 ms −28%

Non-batched update timings remain unchanged.

@github-actions

Copy link
Copy Markdown

Size Change: +59 B (+0.07%)

Total Size: 79.5 kB

📦 View Changed
Filename Size Change
compat/dist/compat.js 4.2 kB +14 B (+0.33%)
compat/dist/compat.mjs 4.12 kB +15 B (+0.37%)
compat/dist/compat.module.js 4.12 kB +15 B (+0.37%)
compat/dist/compat.umd.js 4.27 kB +15 B (+0.35%)
ℹ️ View Unchanged
Filename Size
debug/dist/debug.js 3.85 kB
debug/dist/debug.mjs 3.85 kB
debug/dist/debug.module.js 3.85 kB
debug/dist/debug.umd.js 3.93 kB
devtools/dist/devtools.js 260 B
devtools/dist/devtools.mjs 274 B
devtools/dist/devtools.module.js 274 B
devtools/dist/devtools.umd.js 346 B
dist/preact.js 4.83 kB
dist/preact.min.js 4.84 kB
dist/preact.min.module.js 4.85 kB
dist/preact.min.umd.js 4.86 kB
dist/preact.mjs 4.85 kB
dist/preact.module.js 4.85 kB
dist/preact.umd.js 4.87 kB
hooks/dist/hooks.js 1.51 kB
hooks/dist/hooks.mjs 1.54 kB
hooks/dist/hooks.module.js 1.54 kB
hooks/dist/hooks.umd.js 1.58 kB
jsx-runtime/dist/jsxRuntime.js 1.01 kB
jsx-runtime/dist/jsxRuntime.mjs 985 B
jsx-runtime/dist/jsxRuntime.module.js 985 B
jsx-runtime/dist/jsxRuntime.umd.js 1.08 kB
test-utils/dist/testUtils.js 473 B
test-utils/dist/testUtils.mjs 477 B
test-utils/dist/testUtils.module.js 477 B
test-utils/dist/testUtils.umd.js 555 B

compressed-size-action

@github-actions

Copy link
Copy Markdown

📊 Tachometer Benchmark Results

Summary

duration

  • create10k: unsure 🔍 -0% - +1% (-2.76ms - +6.31ms)
    preact-local vs preact-main
  • filter-list: unsure 🔍 -2% - +1% (-0.40ms - +0.11ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -4% - +1% (-2.23ms - +0.80ms)
    preact-local vs preact-main
  • many-updates: unsure 🔍 -0% - +1% (-0.08ms - +0.17ms)
    preact-local vs preact-main
  • replace1k: unsure 🔍 -1% - +2% (-0.64ms - +1.04ms)
    preact-local vs preact-main
  • text-update: unsure 🔍 -3% - +6% (-0.05ms - +0.10ms)
    preact-local vs preact-main
  • todo: unsure 🔍 -2% - +1% (-0.58ms - +0.31ms)
    preact-local vs preact-main
  • update10th1k: unsure 🔍 -5% - +2% (-1.47ms - +0.68ms)
    preact-local vs preact-main

usedJSHeapSize

  • create10k: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-main
  • filter-list: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-main
  • hydrate1k: unsure 🔍 -3% - +1% (-0.17ms - +0.03ms)
    preact-local vs preact-main
  • many-updates: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-main
  • replace1k: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-main
  • text-update: unsure 🔍 -2% - +4% (-0.02ms - +0.04ms)
    preact-local vs preact-main
  • todo: unsure 🔍 -0% - +0% (-0.00ms - +0.00ms)
    preact-local vs preact-main
  • update10th1k: unsure 🔍 -0% - +0% (-0.01ms - +0.01ms)
    preact-local vs preact-main

Results

create10k

duration

VersionAvg timevs preact-localvs preact-main
preact-local810.03ms - 816.08ms-unsure 🔍
-0% - +1%
-2.76ms - +6.31ms
preact-main807.90ms - 814.66msunsure 🔍
-1% - +0%
-6.31ms - +2.76ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local19.21ms - 19.21ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
preact-main19.21ms - 19.21msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-
filter-list

duration

VersionAvg timevs preact-localvs preact-main
preact-local16.56ms - 16.68ms-unsure 🔍
-2% - +1%
-0.40ms - +0.11ms
preact-main16.52ms - 17.01msunsure 🔍
-1% - +2%
-0.11ms - +0.40ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local1.56ms - 1.57ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
preact-main1.56ms - 1.57msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-
hydrate1k

duration

VersionAvg timevs preact-localvs preact-main
preact-local57.20ms - 58.94ms-unsure 🔍
-4% - +1%
-2.23ms - +0.80ms
preact-main57.55ms - 60.03msunsure 🔍
-1% - +4%
-0.80ms - +2.23ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local5.02ms - 5.03ms-unsure 🔍
-3% - +1%
-0.17ms - +0.03ms
preact-main5.00ms - 5.20msunsure 🔍
-1% - +3%
-0.03ms - +0.17ms
-
many-updates

duration

VersionAvg timevs preact-localvs preact-main
preact-local16.40ms - 16.57ms-unsure 🔍
-0% - +1%
-0.08ms - +0.17ms
preact-main16.35ms - 16.53msunsure 🔍
-1% - +0%
-0.17ms - +0.08ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local3.73ms - 3.73ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
preact-main3.73ms - 3.73msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-
replace1k
  • Browser: chrome-headless
  • Sample size: 100
  • Built by: CI #5708
  • Commit: 3393c0b

duration

VersionAvg timevs preact-localvs preact-main
preact-local55.38ms - 56.65ms-unsure 🔍
-1% - +2%
-0.64ms - +1.04ms
preact-main55.26ms - 56.37msunsure 🔍
-2% - +1%
-1.04ms - +0.64ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local3.02ms - 3.02ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
preact-main3.02ms - 3.02msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-

run-warmup-0

VersionAvg timevs preact-localvs preact-main
preact-local27.52ms - 28.29ms-unsure 🔍
-1% - +3%
-0.17ms - +0.95ms
preact-main27.11ms - 27.93msunsure 🔍
-3% - +1%
-0.95ms - +0.17ms
-

run-warmup-1

VersionAvg timevs preact-localvs preact-main
preact-local31.64ms - 32.71ms-unsure 🔍
-3% - +2%
-0.87ms - +0.65ms
preact-main31.74ms - 32.83msunsure 🔍
-2% - +3%
-0.65ms - +0.87ms
-

run-warmup-2

VersionAvg timevs preact-localvs preact-main
preact-local31.59ms - 32.84ms-unsure 🔍
-4% - +1%
-1.24ms - +0.49ms
preact-main31.99ms - 33.19msunsure 🔍
-2% - +4%
-0.49ms - +1.24ms
-

run-warmup-3

VersionAvg timevs preact-localvs preact-main
preact-local25.89ms - 26.56ms-unsure 🔍
-1% - +2%
-0.27ms - +0.59ms
preact-main25.80ms - 26.33msunsure 🔍
-2% - +1%
-0.59ms - +0.27ms
-

run-warmup-4

VersionAvg timevs preact-localvs preact-main
preact-local22.87ms - 24.01ms-unsure 🔍
-1% - +6%
-0.25ms - +1.30ms
preact-main22.38ms - 23.44msunsure 🔍
-6% - +1%
-1.30ms - +0.25ms
-

run-final

VersionAvg timevs preact-localvs preact-main
preact-local21.04ms - 21.48ms-unsure 🔍
-1% - +1%
-0.24ms - +0.30ms
preact-main21.07ms - 21.39msunsure 🔍
-1% - +1%
-0.30ms - +0.24ms
-
text-update
  • Browser: chrome-headless
  • Sample size: 220
  • Built by: CI #5708
  • Commit: 3393c0b

duration

VersionAvg timevs preact-localvs preact-main
preact-local1.72ms - 1.82ms-unsure 🔍
-3% - +6%
-0.05ms - +0.10ms
preact-main1.69ms - 1.80msunsure 🔍
-5% - +3%
-0.10ms - +0.05ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local1.02ms - 1.07ms-unsure 🔍
-2% - +4%
-0.02ms - +0.04ms
preact-main1.01ms - 1.06msunsure 🔍
-4% - +2%
-0.04ms - +0.02ms
-
todo

duration

VersionAvg timevs preact-localvs preact-main
preact-local33.25ms - 33.79ms-unsure 🔍
-2% - +1%
-0.58ms - +0.31ms
preact-main33.30ms - 34.01msunsure 🔍
-1% - +2%
-0.31ms - +0.58ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local1.26ms - 1.26ms-unsure 🔍
-0% - +0%
-0.00ms - +0.00ms
preact-main1.26ms - 1.26msunsure 🔍
-0% - +0%
-0.00ms - +0.00ms
-
update10th1k

duration

VersionAvg timevs preact-localvs preact-main
preact-local30.33ms - 31.83ms-unsure 🔍
-5% - +2%
-1.47ms - +0.68ms
preact-main30.70ms - 32.25msunsure 🔍
-2% - +5%
-0.68ms - +1.47ms
-

usedJSHeapSize

VersionAvg timevs preact-localvs preact-main
preact-local2.99ms - 3.00ms-unsure 🔍
-0% - +0%
-0.01ms - +0.01ms
preact-main2.99ms - 3.00msunsure 🔍
-0% - +0%
-0.01ms - +0.01ms
-

tachometer-reporter-action v2 for CI

@JoviDeCroock
JoviDeCroock merged commit f27f3ec into v10.x Jul 30, 2026
12 checks passed
@JoviDeCroock
JoviDeCroock deleted the flush-sync-batch branch July 30, 2026 10:05
JoviDeCroock added a commit to ssssota/preactjs_preact that referenced this pull request Jul 31, 2026
Previously, flushSync temporarily configured options.debounceRendering
to execute every scheduled render immediately. This made updates
synchronous, but it also caused each state setter to render
independently instead of batching all updates performed inside the
callback into one synchronous commit.

Capture the scheduled render callback while the user callback runs, then
flush it once before returning. The previous debounce function is
restored in a finally block.

Mirrors preactjs#5173 (v10.x).
@JoviDeCroock JoviDeCroock mentioned this pull request Jul 31, 2026
valthon added a commit to valthon/zigapagos that referenced this pull request Aug 8, 2026
… injection fix

Supersedes dependabot PR #124 (happy-dom 20.11.0 -> 20.11.1); the sweep
below was researched against each package's releases rather than taking the
grouped bump as-is.

preact-render-to-string ^6.6.2 -> ^6.7.0 is the change that matters on its
own. 6.7.0 reordered the attribute serializer so UNSAFE_NAME rejection runs
before namespace normalization (preactjs/preact-render-to-string#461):
previously an attribute key that looked namespaced but contained spaces or
`>` was rewritten and emitted rather than dropped — markup injection through
prop KEYS, e.g. `xlinkHref><script>…`. That lands on our only SSR path:
runtime/src/core.ts re-exports renderToString and runtime/sidecar/render.ts
drives it with author-content props from src/islands/props.zig. The lockfile
already resolved 6.7.0, so built sites were safe; the declared ^6.6.2 was
the hole, because any fresh resolution could legally land back on the
vulnerable 6.6.2. Raising the floor closes it.

preact ^10.29.7 -> ^10.29.8: two perf fixes — flushSync now actually
batches (preactjs/preact#5173; we re-export it but never call it) and
retained-subtree traversal is skipped after sCU/memo bailouts (#5182).
Diff-layer change, so validated through bun test (750/0) plus a full
examples/tsx-site build (SSR + hydration bundle + CSP emitters).

happy-dom + @happy-dom/global-registrator ^20.11.0 -> ^20.11.2 (lockstep,
as they release): 20.11.1 stops constructing DOMException on the
query-selector hot path (a straight speedup for this DOM-heavy suite);
20.11.2 fixes MutationObserver callbacks being held only via WeakRef and
silently dying after a GC — latent here, but exactly the class of defect
that presents as an unreproducible flaky test.

typescript stays at ^6.0.3 — and permanently, not pending a 6.1: 6.0.3 is
the final release of the JavaScript codebase (microsoft/TypeScript#62963,
the 6.0 line is in maintenance mode; the next stable on the registry is the
Go-based 7.0.2, which ships no JS compiler API). The dependabot.yml cap
below 7.0.0 and its unblock conditions (7.1's new API, expected ~Oct 2026,
then porting the three ts.createSourceFile call sites) are unchanged.

All three lockfiles are regenerated in this commit (rm bun.lock + install,
per the dependabot.yml note — site/ and examples/tsx-site embed their own
copy of @z/runtime's resolved set and a plain install does not refresh it),
under the newly pinned bun 1.3.14 so the lockfiles are canonical for the
toolchain that CI runs. The two regenerated trees are pinned back to
"configVersion": 0: a from-scratch lockfile is treated as a new project and
stamped configVersion 1, which flips future installs to the isolated
linker — a silent node_modules-layout change this repo doesn't want, since
props_check.zig resolves tsc from the website root's hoisted tree. 0 is the
value runtime/'s lockfile already carries and preserves hoisted semantics;
frozen installs from scratch were verified to honor it (no .bun store,
tsc resolvable at top level).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
HeyItsGilbert added a commit to HeyItsGilbert/DigitalGarden that referenced this pull request Aug 23, 2026
![snyk-top-banner](https://res.cloudinary.com/snyk/image/upload/r-d/scm-platform/snyk-pull-requests/pr-banner-default.svg)


<h3>Snyk has created this PR to upgrade preact from 10.29.7 to
10.29.8.</h3>

:information_source: Keep your dependencies up-to-date. This makes it
easier to fix existing vulnerabilities and to more quickly identify and
fix newly disclosed vulnerabilities when they affect your project.

<hr/>


- The recommended version is **1 version** ahead of your current
version.

- The recommended version was released **21 days ago**.


#### Breaking Change Risk

![Merge Risk:
Low](https://img.shields.io/badge/Merge%20Risk%3A%20Low-006400?style=for-the-badge)

> **Notice:** This assessment is enhanced by AI.


<details>
<summary><b>Release notes</b></summary>
<br/>
  <details>
    <summary>Package name: <b>preact</b></summary>
    <ul>
      <li>
<b>10.29.8</b> - <a
href="https://redirect.github.com/preactjs/preact/releases/tag/10.29.8">2026-08-01</a></br><h2>Performance</h2>
<ul>
<li>Batch updates in flushSync (<a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="4946206960"
data-permission-text="Title is private"
data-url="preactjs/preact#5173"
data-hovercard-type="pull_request"
data-hovercard-url="/preactjs/preact/pull/5173/hovercard"
href="https://redirect.github.com/preactjs/preact/pull/5173">#5173</a>,
thanks <a class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/JoviDeCroock/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/JoviDeCroock">@ JoviDeCroock</a>)</li>
<li>Avoid traversing retained subtrees (<a class="issue-link
js-issue-link" data-error-text="Failed to load title"
data-id="5010720925" data-permission-text="Title is private"
data-url="preactjs/preact#5182"
data-hovercard-type="pull_request"
data-hovercard-url="/preactjs/preact/pull/5182/hovercard"
href="https://redirect.github.com/preactjs/preact/pull/5182">#5182</a>,
thanks <a class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/JoviDeCroock/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/JoviDeCroock">@ JoviDeCroock</a>)</li>
</ul>
      </li>
      <li>
<b>10.29.7</b> - <a
href="https://redirect.github.com/preactjs/preact/releases/tag/10.29.7">2026-07-08</a></br><h2>Maintenance</h2>
<ul>
<li>Make RTS optional peer dep (<a class="issue-link js-issue-link"
data-error-text="Failed to load title" data-id="4839540392"
data-permission-text="Title is private"
data-url="preactjs/preact#5150"
data-hovercard-type="pull_request"
data-hovercard-url="/preactjs/preact/pull/5150/hovercard"
href="https://redirect.github.com/preactjs/preact/pull/5150">#5150</a>,
thanks <a class="user-mention notranslate" data-hovercard-type="user"
data-hovercard-url="/users/JoviDeCroock/hovercard"
data-octo-click="hovercard-link-click"
data-octo-dimensions="link_type:self"
href="https://redirect.github.com/JoviDeCroock">@ JoviDeCroock</a>)</li>
</ul>
      </li>
    </ul>
from <a
href="https://redirect.github.com/preactjs/preact/releases">preact
GitHub release notes</a>
  </details>
</details>

---

> [!IMPORTANT]
>
> - Check the changes in this PR to ensure they won't cause issues with
your project.
> - This PR was automatically created by Snyk using the credentials of a
real user.

---

**Note:** _You are seeing this because you or someone else with access
to this repository has authorized Snyk to open upgrade PRs._

**For more information:** <img
src="https://api.segment.io/v1/pixel/track?data=eyJ3cml0ZUtleSI6InJyWmxZcEdHY2RyTHZsb0lYd0dUcVg4WkFRTnNCOUEwIiwiYW5vbnltb3VzSWQiOiI1NGI1MmJmOS05Yjk4LTQxOTktOTljNS0zZmM0NTZhNmEzYjIiLCJldmVudCI6IlBSIHZpZXdlZCIsInByb3BlcnRpZXMiOnsicHJJZCI6IjU0YjUyYmY5LTliOTgtNDE5OS05OWM1LTNmYzQ1NmE2YTNiMiJ9fQ=="
width="0" height="0"/>

> - 🧐 [View latest project
report](https://app.snyk.io/org/heyitsgilbert/project/b4d35463-698d-4f18-a0ef-2b34051c2638?utm_source&#x3D;github&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr)
> - 📜 [Customise PR
templates](https://docs.snyk.io/scan-using-snyk/pull-requests/snyk-fix-pull-or-merge-requests/customize-pr-templates?utm_source=&utm_content=fix-pr-template)
> - 🛠 [Adjust upgrade PR
settings](https://app.snyk.io/org/heyitsgilbert/project/b4d35463-698d-4f18-a0ef-2b34051c2638/settings/integration?utm_source&#x3D;github&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr)
> - 🔕 [Ignore this dependency or unsubscribe from future upgrade
PRs](https://app.snyk.io/org/heyitsgilbert/project/b4d35463-698d-4f18-a0ef-2b34051c2638/settings/integration?pkg&#x3D;preact&amp;utm_source&#x3D;github&amp;utm_medium&#x3D;referral&amp;page&#x3D;upgrade-pr#auto-dep-upgrades)

[//]: #
'snyk:metadata:{"breakingChangeRiskLevel":"low","FF_showPullRequestBreakingChanges":true,"FF_showPullRequestBreakingChangesWebSearch":false,"customTemplate":{"variablesUsed":[],"fieldsUsed":[]},"dependencies":[{"name":"preact","from":"10.29.7","to":"10.29.8"}],"env":"prod","hasFixes":false,"isBreakingChange":false,"isMajorUpgrade":false,"issuesToFix":[],"prId":"54b52bf9-9b98-4199-99c5-3fc456a6a3b2","prPublicId":"54b52bf9-9b98-4199-99c5-3fc456a6a3b2","packageManager":"npm","priorityScoreList":[],"projectPublicId":"b4d35463-698d-4f18-a0ef-2b34051c2638","projectUrl":"https://app.snyk.io/org/heyitsgilbert/project/b4d35463-698d-4f18-a0ef-2b34051c2638?utm_source=github&utm_medium=referral&page=upgrade-pr","prType":"upgrade","templateFieldSources":{"branchName":"default","commitMessage":"default","description":"default","title":"default"},"templateVariants":[],"type":"auto","upgrade":[],"upgradeInfo":{"versionsDiff":1,"publishedDate":"2026-08-01T09:59:54.572Z"},"vulns":[]}'

Co-authored-by: snyk-bot <snyk-bot@snyk.io>
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.

2 participants