Skip to content

feat(react): add element template alog diagnostics#2550

Merged
Yradex merged 1 commit into
lynx-family:mainfrom
Yradex:slice/element-template/01
Apr 30, 2026
Merged

feat(react): add element template alog diagnostics#2550
Yradex merged 1 commit into
lynx-family:mainfrom
Yradex:slice/element-template/01

Conversation

@Yradex
Copy link
Copy Markdown
Collaborator

@Yradex Yradex commented Apr 30, 2026

Summary by CodeRabbit

  • New Features

    • Added diagnostic debug logging for Element Template operations, providing formatted visibility into template updates, hydration, and patch operations when debug mode is enabled.
  • Tests

    • Added comprehensive test coverage for Element Template debug logging utilities, including formatting helpers and debug output validation across commit, hydration, and patch operations.

Overview

  • Add Element Template diagnostic logging for the hydrate and update path so ET command streams can be inspected through the existing ALog debug channel.
  • Keep the diagnostics gated by __ALOG__, so the normal runtime path does not format command streams, print background trees, or emit extra debug output.
  • Include an empty changeset because this is internal diagnostic coverage and does not change public APIs, exports, runtime/native contracts, or default production behavior.

Key Points

  • The new ET debug helper decodes the compact update command stream into named operations such as createTemplate, setAttribute, insertNode, and removeNode.
  • Hydration logging now records the main-thread serialized payload and the background ET tree before and after hydration, which makes slot and identity mismatches easier to inspect.
  • Background commit and main-thread patch logging share the same command formatter, so the BTS-to-MTS update payload and MTS patch application are described with the same operation names and slot indexes.

Diagnostic Output

When __ALOG__ is enabled, compact update commands are logged in a reviewer-readable shape:

{
  "ops": [
    {
      "op": "setAttribute",
      "targetId": 1,
      "attrSlotIndex": 0,
      "value": "next"
    }
  ],
  "flushOptions": {},
  "flowIds": {}
}

The formatted output is diagnostic-only. The wire protocol remains the existing compact command stream consumed by the ET patch executor.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).
  • Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 30, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: cc0cbb1f-5177-4bfc-a4be-7a64e89c6265

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • ✅ Review completed - (🔄 Check again to review again)
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented Apr 30, 2026

🦋 Changeset detected

Latest commit: a0e84cf

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

This PR includes changesets to release 0 packages

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 30, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ All tests successful. No failed tests found.

📢 Thoughts on this report? Let us know!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Apr 30, 2026

Merging this PR will improve performance by 18.85%

⚡ 1 improved benchmark
✅ 80 untouched benchmarks
⏩ 26 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
008-many-use-state-destroyBackground 9.5 ms 8 ms +18.85%

Comparing Yradex:slice/element-template/01 (a0e84cf) with main (7abb0a9)

Open in CodSpeed

Footnotes

  1. 26 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 30, 2026

Web Explorer

#9310 Bundle Size — 900.03KiB (0%).

a0e84cf(current) vs 7abb0a9 main#9309(baseline)

Bundle metrics  Change 1 change
                 Current
#9310
     Baseline
#9309
No change  Initial JS 44.46KiB 44.46KiB
No change  Initial CSS 2.22KiB 2.22KiB
No change  Cache Invalidation 0% 0%
No change  Chunks 9 9
No change  Assets 11 11
Change  Modules 229(-0.43%) 230
No change  Duplicate Modules 11 11
No change  Duplicate Code 27.28% 27.28%
No change  Packages 10 10
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#9310
     Baseline
#9309
No change  JS 495.9KiB 495.9KiB
No change  Other 401.92KiB 401.92KiB
No change  CSS 2.22KiB 2.22KiB

Bundle analysis reportBranch Yradex:slice/element-template/01Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 30, 2026

React External

#852 Bundle Size — 680.82KiB (0%).

a0e84cf(current) vs 7abb0a9 main#851(baseline)

Bundle metrics  no changes
                 Current
#852
     Baseline
#851
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 17 17
No change  Duplicate Modules 5 5
No change  Duplicate Code 8.59% 8.59%
No change  Packages 0 0
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#852
     Baseline
#851
No change  Other 680.82KiB 680.82KiB

Bundle analysis reportBranch Yradex:slice/element-template/01Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 30, 2026

React Example (Element Template)

#5 Bundle Size — 198.61KiB (0%).

a0e84cf(current) vs 7abb0a9 main#4(baseline)

Bundle metrics  Change 2 changes
                 Current
#5
     Baseline
#4
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 4 4
Change  Modules 77(-3.75%) 80
No change  Duplicate Modules 23 23
Change  Duplicate Code 40.53%(-0.37%) 40.68%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#5
     Baseline
#4
No change  IMG 145.76KiB 145.76KiB
No change  Other 52.85KiB 52.85KiB

Bundle analysis reportBranch Yradex:slice/element-template/01Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 30, 2026

React Example

#7737 Bundle Size — 225.52KiB (0%).

a0e84cf(current) vs 7abb0a9 main#7736(baseline)

Bundle metrics  no changes
                 Current
#7737
     Baseline
#7736
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 180 180
No change  Duplicate Modules 69 69
No change  Duplicate Code 44.54% 44.54%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#7737
     Baseline
#7736
No change  IMG 145.76KiB 145.76KiB
No change  Other 79.77KiB 79.77KiB

Bundle analysis reportBranch Yradex:slice/element-template/01Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented Apr 30, 2026

React MTF Example

#869 Bundle Size — 196.68KiB (0%).

a0e84cf(current) vs 7abb0a9 main#868(baseline)

Bundle metrics  no changes
                 Current
#869
     Baseline
#868
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 3 3
No change  Modules 174 174
No change  Duplicate Modules 66 66
No change  Duplicate Code 44.05% 44.05%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#869
     Baseline
#868
No change  IMG 111.23KiB 111.23KiB
No change  Other 85.45KiB 85.45KiB

Bundle analysis reportBranch Yradex:slice/element-template/01Project dashboard


Generated by RelativeCIDocumentationReport issue

@Yradex Yradex marked this pull request as ready for review April 30, 2026 08:50
@Yradex Yradex requested review from HuJean and hzy as code owners April 30, 2026 08:50
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
packages/react/runtime/__test__/element-template/debug/alog.test.ts (2)

84-103: ⚡ Quick win

Make the tree-summary assertions less brittle (IDs + exact substrings).

This test asserts exact node IDs in the rendered string (e.g. root#1, _et_card#2, __et_builtin_raw_text__#3) and specific substring formatting like elementSlots[0]: [3], plus not.toContain('elementSlots[1]').

Two ways to make it more resilient:

  • Derive expected #<id> values from the created BackgroundElementTemplateInstance instances instead of assuming #1/#2/#3.
  • Prefer verifying semantic presence/omission (e.g., elementSlots[0] includes the text id) using ids computed from the instances, rather than hard-coding the slot rendering to [3].

This keeps the test meaningful even if the printer’s formatting changes slightly.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/react/runtime/__test__/element-template/debug/alog.test.ts` around
lines 84 - 103, The test hard-codes node IDs and exact slot formatting making it
brittle; update the assertions to compute expected ids from the created
BackgroundElementTemplateInstance instances (root, card, text) and assert
presence/absence semantically via printElementTemplateTreeToString output: check
that the string contains `${root.id}`/`${card.id}`/`${text.id}` (or equivalent)
and that elementSlots[0] references the computed text id, assert elementSlots[1]
is omitted semantically (e.g., no mention of the card’s second slot or an empty
slot), and verify attributeSlots contain the expected attribute values from the
instances rather than exact bracket formatting. Ensure you locate and change
assertions around printElementTemplateTreeToString,
BackgroundElementTemplateInstance, elementSlots and attributeSlots in the test.

12-15: ⚡ Quick win

Avoid coupling to nextId internals in beforeEach.

This test suite hard-resets backgroundElementTemplateInstanceManager.nextId = 0. If the manager’s internal ID strategy changes (e.g., different initial value, separate counters), these tests can start failing even when behavior is still correct.

Consider adding a test-only reset helper on the manager (preferred), or at least derive the expected #<id> suffixes from the created instances (root, card, text) rather than assuming #1/#2/#3.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/react/runtime/__test__/element-template/debug/alog.test.ts` around
lines 12 - 15, The tests currently mutate
backgroundElementTemplateInstanceManager.nextId directly in beforeEach; instead
add a test-only reset method on backgroundElementTemplateInstanceManager (e.g.,
resetForTests or clearAndReset) that clears state and resets any internal
counters, call that from beforeEach, and update tests to rely on instance
identifiers returned from created instances (root, card, text) rather than
hard-coding "#1/#2/#3" — locate and modify
backgroundElementTemplateInstanceManager (methods like clear and nextId) to add
the reset helper and update the test file to read ids from the created instance
objects or the manager API when asserting suffixes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/react/runtime/__test__/element-template/debug/alog.test.ts`:
- Around line 84-103: The test hard-codes node IDs and exact slot formatting
making it brittle; update the assertions to compute expected ids from the
created BackgroundElementTemplateInstance instances (root, card, text) and
assert presence/absence semantically via printElementTemplateTreeToString
output: check that the string contains `${root.id}`/`${card.id}`/`${text.id}`
(or equivalent) and that elementSlots[0] references the computed text id, assert
elementSlots[1] is omitted semantically (e.g., no mention of the card’s second
slot or an empty slot), and verify attributeSlots contain the expected attribute
values from the instances rather than exact bracket formatting. Ensure you
locate and change assertions around printElementTemplateTreeToString,
BackgroundElementTemplateInstance, elementSlots and attributeSlots in the test.
- Around line 12-15: The tests currently mutate
backgroundElementTemplateInstanceManager.nextId directly in beforeEach; instead
add a test-only reset method on backgroundElementTemplateInstanceManager (e.g.,
resetForTests or clearAndReset) that clears state and resets any internal
counters, call that from beforeEach, and update tests to rely on instance
identifiers returned from created instances (root, card, text) rather than
hard-coding "#1/#2/#3" — locate and modify
backgroundElementTemplateInstanceManager (methods like clear and nextId) to add
the reset helper and update the test file to read ids from the created instance
objects or the manager API when asserting suffixes.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 73f23fac-2237-413e-a74c-84533c1a5a5b

📥 Commits

Reviewing files that changed from the base of the PR and between 7abb0a9 and a0e84cf.

📒 Files selected for processing (9)
  • .changeset/element-template-alog-diagnostics.md
  • packages/react/runtime/__test__/element-template/debug/alog.test.ts
  • packages/react/runtime/__test__/element-template/runtime/background/commit-hook.test.ts
  • packages/react/runtime/__test__/element-template/runtime/hydration/hydration-listener.test.ts
  • packages/react/runtime/__test__/element-template/runtime/patch/patch-listener-alog.test.ts
  • packages/react/runtime/src/element-template/background/commit-hook.ts
  • packages/react/runtime/src/element-template/background/hydration-listener.ts
  • packages/react/runtime/src/element-template/debug/alog.ts
  • packages/react/runtime/src/element-template/native/patch-listener.ts

@Yradex Yradex merged commit 08aa667 into lynx-family:main Apr 30, 2026
54 checks passed
@Yradex Yradex deleted the slice/element-template/01 branch April 30, 2026 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants