Skip to content

Skip notifications while innerHTML builds its fragment - #160

Open
natemoo-re wants to merge 1 commit into
natemoo-re/ui-inner-html-setterfrom
natemoo-re/ui-inner-html-notify
Open

natemoo-re wants to merge 1 commit into
natemoo-re/ui-inner-html-setterfrom
natemoo-re/ui-inner-html-notify

Conversation

@natemoo-re

Copy link
Copy Markdown
Member

What does this PR do?

Stacked on #159.

Stops the innerHTML setter from sending change notifications while it builds the parsed fragment. Before this change, every node the sink inserted, and every attribute it set, notified the document, so RenderApi.request added the node and its detached ancestors to the next frame's change set. Parsed nodes never need those marks. Layout reuses an element's previous output, or its cached style, only after that element has been laid out (opened) in an earlier frame. A node the parser just created hasn't been, so marking it changed does nothing.

The marks the replay does need come from the swap into the target element: removing the old children and inserting the new top-level nodes marks the element, its ancestors and the new children. The swap still notifies as before.

  • Document gets a buildDetached(document, build) hook, using the same static {} pattern as createParsedElement. While build runs, the document drops notifications. It restores the previous state in finally, so a parse error or a nested call can't leave notifications off.
  • parseFragment builds its fragment inside the hook. The setter swaps the result in outside it.

Numbers

These are the median CPU µs to set innerHTML on a connected element, with the real RenderApi as notify. Each figure is the median of 400 sets. The table shows the first of three interleaved before/after runs (load avg ~9–11):

size before (#159) after
478 B 42.4 32.4
1.4 KB 90.1 62.9
4.3 KB 223.3 166.7
geomean 94.9 69.8

Across the three pairs, the geomean went from 95–101 µs to 69–72 µs, about 26–30% lower. With a no-op notify, the same benchmark measures about 62 µs, so what's left above that is the swap's own notifications, which the replay needs.

Tests

  • layout.test.ts: drives the real RenderApi. After two innerHTML replacements, including nested parsed elements that aren't in the change set, each frame's output matches a full layout, and the untouched sibling is still replayed. Suppressing the swap's notifications makes this test fail.
  • parse.test.ts: the swap notifies the host and its new top-level child, and nested parsed nodes are never notified.

Type of change

  • Bug fix
  • Feature
  • Refactor (no behavior change)
  • Documentation
  • Performance improvement
  • Tests
  • Chore (dependencies, CI, tooling)

Checklist

  • All tests pass (pnpm test)
  • Files are formatted (pnpm format)
  • I have added/updated tests for my changes (if applicable)
  • I have added a changeset

AI-generated code disclosure

  • This PR includes AI-generated code

@pkg-pr-new

pkg-pr-new Bot commented Dec 6, 2026

Copy link
Copy Markdown

commit: c582484

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.

1 participant