Repository navigation
Hydrate the menu bar - #43
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Twelfth lesson in my Angular guide: server-side rendering and hydration. The feature slice makes the menu bar hydrate instead of being thrown away.
What shipped
Prerendered pages no longer show the build time. The menu bar clock rendered on the server, so every Thoughts page shipped the clock as it read during the build, until the JavaScript loaded. From the 1.4.10 build:
nulluntil the browser takes over, and starts inafterNextRender, which never runs on the server.effectwith no signal dependencies, guarded byisPlatformBrowser, that only existed to start asetInterval.The menu bar hydrates. It was marked
ngSkipHydrationto hide the server/browser difference, so the browser discarded the server DOM for the whole bar and re-created it. With the difference gone, the attribute is gone. In the new build the bar carries a hydration annotation and an empty clock:menu-bar.server.spec.tsrenders the bar throughrenderApplication, the real server platform, and asserts both. TestBed runs browser-only hooks, so it can't show what the server sends. Both tests failed before the fix:Lesson 12: SSR and hydration (
/thoughts/angular-12-ssr).TransferState; the browser reads it back (and removes it, so a later client-side visit doesn't claim to be server-rendered). In the build:"lesson-12-rendered-at":"2026-11-21T16:33:07.430Z".jsactionmarkup from the lesson 11 page), incremental hydration,PendingTasksandngSkipHydration, then pitfalls and interview Q&A.Bundle. My first version formatted the demo's time with
DatePipe, and the initial bundle went to 407.07 kB, over the 400 kB budget: the same@angular/commontrap as lesson 03.Intl.DateTimeFormatbrought it back to 395.26 kB (394.92 kB before this PR).Commits
Verification
ng test --watch=false: 68 files, 471 tests, exit 0npm run lint: exit 0tsc --noEmit -p tsconfig.app.jsonand-p tsconfig.spec.json: exit 0ng build: exit 0, 81 routes prerendered, initial 395.26 kBthoughts/angular-11-testingandthoughts/angular-12-ssrpages: empty clock,nghon the menu bar, nongskiphydration, the TransferState stamp presentTO-DOs for this PR