Skip to content

feat: pass source element to hydration lifecycle callbacks#7262

Open
radium-v wants to merge 3 commits intomainfrom
users/radium-v/callback-instances
Open

feat: pass source element to hydration lifecycle callbacks#7262
radium-v wants to merge 3 commits intomainfrom
users/radium-v/callback-instances

Conversation

@radium-v
Copy link
Collaborator

@radium-v radium-v commented Feb 9, 2026

Pull Request

📖 Description

This PR updates the elementWillHydrate and elementDidHydrate lifecycle callbacks to pass the source HTMLElement instance instead of the element's tag name string. This enables consumers to interact with the actual element during hydration — for example, to set performance marks or read attributes — rather than only receiving a name, which limits the usefulness of these callbacks.

The HydrationControllerCallbacks interface is now generic over TElement extends HTMLElement, and the callback invocations are wrapped in try/catch to prevent consumer errors from interrupting hydration.

👩‍💻 Reviewer Notes

  • The HydrationControllerCallbacks.lifecycleCallbacks property changed from optional (?) to a required field initialized to {}. This avoids optional chaining at every call site and simplifies the notification helpers.
  • A new performance-metrics test fixture demonstrates using the updated callbacks with the Performance API.

📑 Test Plan

  • Existing lifecycle-callbacks and nested-elements test fixtures updated to use the new source parameter.
  • New performance-metrics test fixture validates that performance.measure entries are created per hydrated element via the callbacks.
  • All existing tests pass.

✅ Checklist

General

  • I have included a change request file using $ npm run change
  • I have added tests for my changes.
  • I have tested my changes.
  • I have updated the project documentation to reflect my changes.
  • I have read the CONTRIBUTING documentation and followed the standards for this project.

Change elementWillHydrate and elementDidHydrate to receive the source
HTMLElement instead of the tag name string. This enables callers to
correlate the willHydrate/didHydrate pair for the same element instance.

Extract inline callback invocations into private notify methods with
try-catch to prevent lifecycle callbacks from blocking hydration.

Make lifecycleCallbacks a non-optional property defaulting to {} to
avoid optional chaining transpilation overhead with ES2015 target.
@radium-v radium-v self-assigned this Feb 9, 2026
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