-
Notifications
You must be signed in to change notification settings - Fork 27.2k
feat(platform-browser): make incremental hydration default behavior #68092
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
kirjs
merged 1 commit into
angular:main
from
thePunderWoman:feat/default-incremental-hydration
Apr 9, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| { | ||
| "dist/browser/main-[hash].js": 232126, | ||
| "dist/browser/main-[hash].js": 240329, | ||
| "dist/browser/polyfills-[hash].js": 35726, | ||
| "dist/browser/event-dispatch-contract.min.js": 476 | ||
| } |
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
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
27 changes: 27 additions & 0 deletions
27
packages/core/schematics/migrations/incremental-hydration/BUILD.bazel
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| load("//tools:defaults.bzl", "ts_project") | ||
|
|
||
| package( | ||
| default_visibility = [ | ||
| "//packages/core/schematics:__pkg__", | ||
| "//packages/core/schematics/test:__pkg__", | ||
| ], | ||
| ) | ||
|
|
||
| ts_project( | ||
| name = "incremental-hydration", | ||
| srcs = glob( | ||
| ["**/*.ts"], | ||
| exclude = ["*.spec.ts"], | ||
| ), | ||
| deps = [ | ||
| "//:node_modules/@angular-devkit/schematics", | ||
| "//:node_modules/@types/node", | ||
| "//:node_modules/typescript", | ||
| "//packages/compiler-cli", | ||
| "//packages/compiler-cli/private", | ||
| "//packages/core/schematics/utils", | ||
| "//packages/core/schematics/utils/tsurge", | ||
| "//packages/core/schematics/utils/tsurge/helpers/angular_devkit", | ||
| "//packages/core/schematics/utils/tsurge/helpers/ast", | ||
| ], | ||
| ) |
20 changes: 20 additions & 0 deletions
20
packages/core/schematics/migrations/incremental-hydration/index.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import {Rule} from '@angular-devkit/schematics'; | ||
| import {runMigrationInDevkit} from '../../utils/tsurge/helpers/angular_devkit'; | ||
| import {IncrementalHydrationMigration} from './migration'; | ||
|
|
||
| export function migrate(): Rule { | ||
| return async (tree, context) => { | ||
| await runMigrationInDevkit({ | ||
| tree, | ||
| getMigration: (fs) => new IncrementalHydrationMigration(), | ||
| }); | ||
| }; | ||
| } |
54 changes: 54 additions & 0 deletions
54
packages/core/schematics/migrations/incremental-hydration/migration.spec.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import {absoluteFrom} from '@angular/compiler-cli'; | ||
| import {initMockFileSystem} from '@angular/compiler-cli/private/testing'; | ||
| import {runTsurgeMigration} from '../../utils/tsurge/testing'; | ||
| import {IncrementalHydrationMigration} from './migration'; | ||
|
|
||
| describe('IncrementalHydration migration', () => { | ||
| beforeEach(() => { | ||
| initMockFileSystem('Native'); | ||
| }); | ||
|
|
||
| it('should not change anything if withIncrementalHydration() is present', async () => { | ||
| const {fs} = await runTsurgeMigration(new IncrementalHydrationMigration(), [ | ||
| { | ||
| name: absoluteFrom('/index.ts'), | ||
| isProgramRootFile: true, | ||
| contents: ` | ||
| import { provideClientHydration, withIncrementalHydration } from '@angular/platform-browser'; | ||
|
|
||
| provideClientHydration(withIncrementalHydration()); | ||
| `, | ||
| }, | ||
| ]); | ||
|
|
||
| const content = fs.readFile(absoluteFrom('/index.ts')); | ||
| expect(content).not.toContain('withNoIncrementalHydration()'); | ||
| expect(content).toContain('withIncrementalHydration()'); | ||
| expect(content).toContain('provideClientHydration()'); | ||
| }); | ||
|
|
||
| it('should add withNoIncrementalHydration() if withIncrementalHydration is absent', async () => { | ||
| const {fs} = await runTsurgeMigration(new IncrementalHydrationMigration(), [ | ||
| { | ||
| name: absoluteFrom('/index.ts'), | ||
| isProgramRootFile: true, | ||
| contents: ` | ||
| import { provideClientHydration } from '@angular/platform-browser'; | ||
|
|
||
| provideClientHydration(); | ||
| `, | ||
| }, | ||
| ]); | ||
|
|
||
| const content = fs.readFile(absoluteFrom('/index.ts')); | ||
| expect(content).toContain('withNoIncrementalHydration()'); | ||
| }); | ||
| }); | ||
123 changes: 123 additions & 0 deletions
123
packages/core/schematics/migrations/incremental-hydration/migration.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| /** | ||
| * @license | ||
| * Copyright Google LLC All Rights Reserved. | ||
| * | ||
| * Use of this source code is governed by an MIT-style license that can be | ||
| * found in the LICENSE file at https://angular.dev/license | ||
| */ | ||
|
|
||
| import {ImportManager} from '@angular/compiler-cli/private/migrations'; | ||
| import ts from 'typescript'; | ||
| import { | ||
| confirmAsSerializable, | ||
| ProgramInfo, | ||
| projectFile, | ||
| Replacement, | ||
| Serializable, | ||
| TextUpdate, | ||
| TsurgeFunnelMigration, | ||
| } from '../../utils/tsurge'; | ||
| import {applyImportManagerChanges} from '../../utils/tsurge/helpers/apply_import_manager'; | ||
|
|
||
| export interface IncrementalHydrationMigrationData { | ||
| replacements: Replacement[]; | ||
| } | ||
|
|
||
| export class IncrementalHydrationMigration extends TsurgeFunnelMigration< | ||
| IncrementalHydrationMigrationData, | ||
| IncrementalHydrationMigrationData | ||
| > { | ||
| override async analyze( | ||
| info: ProgramInfo, | ||
| ): Promise<Serializable<IncrementalHydrationMigrationData>> { | ||
| const {sourceFiles, program} = info; | ||
| const typeChecker = program.getTypeChecker(); | ||
| const replacements: Replacement[] = []; | ||
| const importManager = new ImportManager(); | ||
| const printer = ts.createPrinter(); | ||
|
|
||
| for (const sf of sourceFiles) { | ||
| ts.forEachChild(sf, function visit(node: ts.Node) { | ||
| if ( | ||
| ts.isCallExpression(node) && | ||
| ts.isIdentifier(node.expression) && | ||
| node.expression.text === 'provideClientHydration' | ||
| ) { | ||
| let hasIncremental = false; | ||
| let incrementalArgNode: ts.CallExpression | null = null; | ||
|
|
||
| for (const arg of node.arguments) { | ||
| if ( | ||
| ts.isCallExpression(arg) && | ||
| ts.isIdentifier(arg.expression) && | ||
| arg.expression.text === 'withIncrementalHydration' | ||
| ) { | ||
| hasIncremental = true; | ||
| incrementalArgNode = arg; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
| if (!hasIncremental) { | ||
| // Add withNoIncrementalHydration() | ||
| const withNoIncrementalExpr = importManager.addImport({ | ||
| exportModuleSpecifier: '@angular/platform-browser', | ||
| exportSymbolName: 'withNoIncrementalHydration', | ||
| requestedFile: sf, | ||
| }); | ||
|
|
||
| const exprText = printer.printNode(ts.EmitHint.Unspecified, withNoIncrementalExpr, sf); | ||
|
|
||
| const insertPos = node.arguments.end; | ||
| const toInsert = node.arguments.length > 0 ? `, ${exprText}()` : `${exprText}()`; | ||
|
|
||
| replacements.push( | ||
| new Replacement( | ||
| projectFile(sf, info), | ||
| new TextUpdate({ | ||
| position: insertPos, | ||
| end: insertPos, | ||
| toInsert: toInsert, | ||
| }), | ||
| ), | ||
| ); | ||
| } | ||
| } | ||
| ts.forEachChild(node, visit); | ||
| }); | ||
| } | ||
|
|
||
| applyImportManagerChanges(importManager, replacements, sourceFiles, info); | ||
|
|
||
| return confirmAsSerializable({ | ||
| replacements, | ||
| }); | ||
| } | ||
|
|
||
| override async combine( | ||
| unitA: IncrementalHydrationMigrationData, | ||
| unitB: IncrementalHydrationMigrationData, | ||
| ): Promise<Serializable<IncrementalHydrationMigrationData>> { | ||
| return confirmAsSerializable({ | ||
| replacements: [...unitA.replacements, ...unitB.replacements], | ||
| }); | ||
| } | ||
|
|
||
| override async globalMeta( | ||
| combinedData: IncrementalHydrationMigrationData, | ||
| ): Promise<Serializable<IncrementalHydrationMigrationData>> { | ||
| return confirmAsSerializable(combinedData); | ||
| } | ||
|
|
||
| override async stats( | ||
| globalMetadata: IncrementalHydrationMigrationData, | ||
| ): Promise<Serializable<unknown>> { | ||
| return confirmAsSerializable({}); | ||
| } | ||
|
|
||
| override async migrate( | ||
| globalData: IncrementalHydrationMigrationData, | ||
| ): Promise<{replacements: Replacement[]}> { | ||
| return {replacements: globalData.replacements}; | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.