-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(platform-server): surface errors during rendering (#50587)
Prior to this change in some cases errors tht happen during routing were not being surfaced. This is due to the fact that the router has floating promises, and the platform was being destroyed prior to these being settled. PR Close #50587
- Loading branch information
1 parent
4b16884
commit c0d4086
Showing
10 changed files
with
127 additions
and
42 deletions.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
integration/platform-server/projects/ngmodule/prerender.ts
This file contains 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,43 @@ | ||
/** | ||
* @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.io/license | ||
*/ | ||
/* tslint:disable:no-console */ | ||
import 'zone.js/node'; | ||
import {join} from 'path'; | ||
import {renderModule} from '@angular/platform-server'; | ||
import {readFileSync} from 'fs'; | ||
import {AppServerModule} from './src/main.server'; | ||
|
||
const distFolder = join(process.cwd(), 'dist/ngmodule/browser'); | ||
const indexHtml = readFileSync(join(distFolder, 'index.html'), 'utf-8'); | ||
|
||
async function runTest() { | ||
// Test and validate the errors are printed in the console. | ||
const originalConsoleError = console.error; | ||
const errors: string[] = []; | ||
console.error = (error, data) => errors.push(error.toString() + ' ' + data.toString()); | ||
|
||
try { | ||
await renderModule(AppServerModule, { | ||
document: indexHtml, | ||
url: '/error', | ||
}); | ||
} catch {} | ||
|
||
console.error = originalConsoleError; | ||
|
||
// Test case | ||
if (!errors.some((e) => e.includes('Error in resolver'))) { | ||
errors.forEach(console.error); | ||
console.error( | ||
'\nError: expected rendering errors ("Error in resolver") to be printed in the console.\n' | ||
); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
runTest(); |
This file contains 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 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
43 changes: 43 additions & 0 deletions
43
integration/platform-server/projects/standalone/prerender.ts
This file contains 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,43 @@ | ||
/** | ||
* @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.io/license | ||
*/ | ||
/* tslint:disable:no-console */ | ||
import 'zone.js/node'; | ||
import {renderApplication} from '@angular/platform-server'; | ||
import bootstrap from './src/main.server'; | ||
import {join} from 'path'; | ||
import {readFileSync} from 'fs'; | ||
|
||
const distFolder = join(process.cwd(), 'dist/standalone/browser'); | ||
const indexHtml = readFileSync(join(distFolder, 'index.html'), 'utf-8'); | ||
|
||
async function runTest() { | ||
// Test and validate the errors are printed in the console. | ||
const originalConsoleError = console.error; | ||
const errors: string[] = []; | ||
console.error = (error, data) => errors.push(error.toString() + ' ' + data.toString()); | ||
|
||
try { | ||
await renderApplication(bootstrap, { | ||
document: indexHtml, | ||
url: '/error', | ||
}); | ||
} catch {} | ||
|
||
console.error = originalConsoleError; | ||
|
||
// Test case | ||
if (!errors.some((e) => e.includes('Error in resolver'))) { | ||
errors.forEach(console.error); | ||
console.error( | ||
'\nError: expected rendering errors ("Error in resolver") to be printed in the console.\n' | ||
); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
runTest(); |
This file contains 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
28 changes: 0 additions & 28 deletions
28
integration/platform-server/projects/standalone/src/app/app-routing.module.ts
This file was deleted.
Oops, something went wrong.
This file contains 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 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 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 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