Step 20: Event Replay During Hydration

Event Replay

When users interact with the page before hydration is complete, Angular can capture and replay those events once the application becomes interactive.

Benefits:

  • No lost user interactions
  • Seamless user experience
  • Better perceived performance
  • Improved user confidence

Implementation:


// Enable event replay in app.config.ts
provideClientHydration({
  replayEvents: true
})

// Events are automatically captured and replayed
<button (click)="handleClick()">
  Click me during hydration!
</button>
          

Try clicking the cards before hydration is complete. Your clicks will be captured and replayed once the application becomes interactive.

Watch the console to see the events being replayed!

Don't forget to enable event replay in app.config.ts!

Card 1

Card 1

Capturing clicks...

Card 2

Card 2

Capturing clicks...

Card 3

Card 3

Capturing clicks...

Card 4

Card 4

Capturing clicks...

Card 5

Card 5

Capturing clicks...

Card 6

Card 6

Capturing clicks...

Card 7

Card 7

Capturing clicks...

Card 8

Card 8

Capturing clicks...

Card 9

Card 9

Capturing clicks...

Card 10

Card 10

Capturing clicks...

Card 11

Card 11

Capturing clicks...

Card 12

Card 12

Capturing clicks...

Card 13

Card 13

Capturing clicks...

Card 14

Card 14

Capturing clicks...

Card 15

Card 15

Capturing clicks...

Card 16

Card 16

Capturing clicks...

Card 17

Card 17

Capturing clicks...

Card 18

Card 18

Capturing clicks...

Card 19

Card 19

Capturing clicks...

Card 20

Card 20

Capturing clicks...