Skip to content

test(et): migrate background snapshot coverage#2559

Merged
Yradex merged 1 commit into
lynx-family:mainfrom
Yradex:slice/element-template/02
May 6, 2026
Merged

test(et): migrate background snapshot coverage#2559
Yradex merged 1 commit into
lynx-family:mainfrom
Yradex:slice/element-template/02

Conversation

@Yradex
Copy link
Copy Markdown
Collaborator

@Yradex Yradex commented May 6, 2026

Summary by CodeRabbit

  • Tests

    • Expanded test coverage for element template hydration with attribute slots and null handling scenarios.
    • Added tests verifying keyed children order stability in rendering.
  • Bug Fixes

    • Fixed attribute slot synchronization to properly handle null values during hydration.

Overview

This migrates the currently supported BackgroundSnapshotInstance behavior coverage into Element Template runtime tests. The new coverage focuses on ET hydrate diffing, background update emission, keyed reorder stability, and post-hydrate handle continuity.

It also aligns ET hydrate handling for serialized null versus missing background attribute slots with the existing Snapshot behavior, avoiding meaningless update noise caused by JSON serialization.

Key Points

  • Adds ET hydrate tests for attribute diffs, child insert/remove/reorder, empty first-screen rebuild, multi-slot alignment, slot-index isolation, and post-hydrate updates.
  • Adds background instance tests for raw-text updates and attribute-slot removal to null.
  • Adds a Preact-driven background render test file for keyed reorder stability, including randomized shuffles.
  • Adds an empty changeset because this only changes internal tests and an experimental ET hydrate edge case without release-facing API changes.

Verification

  • pnpm exec vitest run --configLoader runner -c __test__/element-template/vitest.config.ts __test__/element-template/runtime/background/hydrate.test.ts __test__/element-template/runtime/background/instance.test.ts __test__/element-template/runtime/background/render/preact.test.tsx

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).

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 6, 2026

🦋 Changeset detected

Latest commit: ec9280d

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 6, 2026

📝 Walkthrough

Walkthrough

This PR adds Element Template runtime test coverage for hydration behavior and Preact child rendering, and applies a minor logic adjustment in hydrate.ts to skip attribute updates when undefined slots are serialized as null from JSON, aligning with Snapshot behavior.

Changes

Element Template Hydration & Rendering Test Coverage

Layer / File(s) Summary
Core Logic Fix
packages/react/runtime/src/element-template/background/hydrate.ts
Added guard in syncAttributeSlots to skip emitting an Attribute update when afterValue is undefined and beforeValue is null, addressing JSON serialization edge case.
Hydration Test Infrastructure
packages/react/runtime/__test__/element-template/runtime/background/hydrate.test.ts
Extended imports with commit context utilities; added resetElementTemplateCommitState() reset in beforeEach; new tests verify attribute slot patching during child creation and null-slot serialization handling.
Instance Update Tests
packages/react/runtime/__test__/element-template/runtime/background/instance.test.ts
Added ElementTemplateUpdateOps import; new tests verify setAttribute updates when raw-text data changes after hydration and explicit null emission when attribute slots are removed.
Preact Rendering Tests
packages/react/runtime/__test__/element-template/runtime/background/render/preact.test.tsx
New test file with App component, shuffle helper, and collector; verifies keyed children order stability under re-render and random reordering stress test (100 iterations).
Metadata
.changeset/quiet-templates-smile.md
Changeset entry documents that no package release is required; change only adds test coverage and aligns internal behavior without public API modifications.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

framework:React

Suggested reviewers

  • HuJean
  • hzy

Poem

🐰 With templates hydrated and nulls now aligned,
Our tests catch the quirks that JSON would bind,
From attributes to preact, each scenario blessed,
The rabbits are hopping—your code passes the test! 🎉

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: migrating background snapshot coverage to Element Template runtime tests, which aligns with the PR objectives.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 6, 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!

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 6, 2026

Web Explorer

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

ec9280d(current) vs 68502b7 main#9352(baseline)

Bundle metrics  Change 2 changes
                 Current
#9358
     Baseline
#9352
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.44%) 228
No change  Duplicate Modules 11 11
Change  Duplicate Code 27.28%(-0.04%) 27.29%
No change  Packages 10 10
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#9358
     Baseline
#9352
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/02Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 6, 2026

React MTF Example

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

ec9280d(current) vs 68502b7 main#911(baseline)

Bundle metrics  no changes
                 Current
#917
     Baseline
#911
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
#917
     Baseline
#911
No change  IMG 111.23KiB 111.23KiB
No change  Other 85.45KiB 85.45KiB

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


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 6, 2026

React External

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

ec9280d(current) vs 68502b7 main#894(baseline)

Bundle metrics  no changes
                 Current
#900
     Baseline
#894
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
#900
     Baseline
#894
No change  Other 680.82KiB 680.82KiB

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


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 6, 2026

React Example

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

ec9280d(current) vs 68502b7 main#7779(baseline)

Bundle metrics  no changes
                 Current
#7785
     Baseline
#7779
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
#7785
     Baseline
#7779
No change  IMG 145.76KiB 145.76KiB
No change  Other 79.77KiB 79.77KiB

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


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link
Copy Markdown

relativeci Bot commented May 6, 2026

React Example with Element Template

#52 Bundle Size — 198.12KiB (+0.01%).

ec9280d(current) vs 68502b7 main#46(baseline)

Bundle metrics  Change 3 changes
                 Current
#52
     Baseline
#46
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
Change  Cache Invalidation 26.42% 26.61%
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.59%(+0.12%) 40.54%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  Change 1 change Regression 1 regression
                 Current
#52
     Baseline
#46
No change  IMG 145.76KiB 145.76KiB
Regression  Other 52.36KiB (+0.05%) 52.34KiB

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


Generated by RelativeCIDocumentationReport issue

@Yradex Yradex marked this pull request as ready for review May 6, 2026 03:49
@Yradex Yradex requested review from HuJean and hzy as code owners May 6, 2026 03:49
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 (1)
packages/react/runtime/__test__/element-template/runtime/background/render/preact.test.tsx (1)

25-25: ⚡ Quick win

Use BUILTIN_RAW_TEXT_TEMPLATE_KEY instead of the hardcoded magic string.

If the constant's value changes, collectRawText would silently stop matching raw-text nodes without any compile-time or import-time signal. The sibling test files (instance.test.ts, hydrate.test.ts) already import the constant.

♻️ Proposed fix

Add the import at the top:

+import { BackgroundElementTemplateInstance, BUILTIN_RAW_TEXT_TEMPLATE_KEY } from '../../../../../src/element-template/background/instance.js';
-import { BackgroundElementTemplateInstance } from '../../../../../src/element-template/background/instance.js';

Then use the constant:

-      if (child.type === '__et_builtin_raw_text__') {
+      if (child.type === BUILTIN_RAW_TEXT_TEMPLATE_KEY) {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/react/runtime/__test__/element-template/runtime/background/render/preact.test.tsx`
at line 25, Replace the hardcoded magic string '__et_builtin_raw_text__' used in
the test assertion with the shared constant BUILTIN_RAW_TEXT_TEMPLATE_KEY: add
an import for BUILTIN_RAW_TEXT_TEMPLATE_KEY at the top of the test file and
update the condition (wherever child.type is compared, e.g., in the
collectRawText/test block) to use BUILTIN_RAW_TEXT_TEMPLATE_KEY so the test
tracks the canonical symbol used by instance.test.ts and hydrate.test.ts.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@packages/react/runtime/__test__/element-template/runtime/background/render/preact.test.tsx`:
- Line 25: Replace the hardcoded magic string '__et_builtin_raw_text__' used in
the test assertion with the shared constant BUILTIN_RAW_TEXT_TEMPLATE_KEY: add
an import for BUILTIN_RAW_TEXT_TEMPLATE_KEY at the top of the test file and
update the condition (wherever child.type is compared, e.g., in the
collectRawText/test block) to use BUILTIN_RAW_TEXT_TEMPLATE_KEY so the test
tracks the canonical symbol used by instance.test.ts and hydrate.test.ts.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ccbed2fc-a91a-498b-b838-04f77666bf6d

📥 Commits

Reviewing files that changed from the base of the PR and between 68502b7 and ec9280d.

📒 Files selected for processing (5)
  • .changeset/quiet-templates-smile.md
  • packages/react/runtime/__test__/element-template/runtime/background/hydrate.test.ts
  • packages/react/runtime/__test__/element-template/runtime/background/instance.test.ts
  • packages/react/runtime/__test__/element-template/runtime/background/render/preact.test.tsx
  • packages/react/runtime/src/element-template/background/hydrate.ts

@Yradex Yradex merged commit 0c6e660 into lynx-family:main May 6, 2026
144 of 149 checks passed
@Yradex Yradex deleted the slice/element-template/02 branch May 6, 2026 06:14
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