Skip to content

feat(hydration): Add a hydrationStarted lifecycle callback#7269

Open
radium-v wants to merge 5 commits intomainfrom
users/radium-v/async-definition-tracking
Open

feat(hydration): Add a hydrationStarted lifecycle callback#7269
radium-v wants to merge 5 commits intomainfrom
users/radium-v/async-definition-tracking

Conversation

@radium-v
Copy link
Collaborator

Pull Request

📖 Description

Adds a hydrationStarted lifecycle callback to HydrationControllerCallbacks and fixes the timing of hydration lifecycle events. Previously, elementWillHydrate fired during the queuing/defer-hydration phase rather than at the point of actual hydration. This PR restructures the hydration pipeline so that:

  • hydrationStarted fires once, immediately before the first element actually begins hydrating
  • elementWillHydrate and elementDidHydrate fire inline with the hydration work, not during registration

Also expands the performance metrics test fixture and adds cross-browser Playwright tests (Chromium, Firefox, WebKit) to validate the full hydration lifecycle ordering.

👩‍💻 Reviewer Notes

  • The HydratableElementController previously used private notifyWillHydrate, notifyDidHydrate, and notifyHydrationComplete methods that wrapped callbacks in try/catch. These have been inlined to reduce indirection — the try/catch blocks remain.
  • The hydrationStarted callback uses a static boolean guard so it fires exactly once per hydration cycle, resetting when hydrationComplete runs.
  • The performance metrics fixture uses detail.sequence on marks to verify ordering even when performance.now() values collide (common in WebKit due to timer coarsening).

📑 Test Plan

  • 11 Playwright tests across 3 browsers (Chromium, Firefox, WebKit) validate the full lifecycle ordering: element-registertemplate-updateelement-definehydration:started → per-element hydrations → hydration:complete
  • Tests use monotonic sequence counters as tiebreakers for timestamp collisions
  • 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.

⏭ Next Steps

  • Consider exposing the sequence counter pattern as a first-class utility for lifecycle instrumentation

@radium-v radium-v self-assigned this Feb 14, 2026
@radium-v radium-v changed the title Users/radium v/async definition tracking feat(hydration): Add a hydrationStarted lifecycle callback Feb 14, 2026
janechu
janechu previously approved these changes Feb 14, 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.

2 participants