-
Notifications
You must be signed in to change notification settings - Fork 27.1k
refactor(core): Throw an error when the document is not initialized. #50143
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
Closed
Closed
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
refactor(core): Throw an error when the document is not initialized.
In case the document is accessed but not available we should throw ASAP an error to prevent non explicit errors.
- Loading branch information
commit 53dbb0d48cb67a2b76867ae8c8ee4c8f26a1c248
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
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 |
|---|---|---|
|
|
@@ -6,6 +6,8 @@ | |
| * found in the LICENSE file at https://angular.io/license | ||
| */ | ||
|
|
||
| import {RuntimeError, RuntimeErrorCode} from '../../errors'; | ||
|
|
||
| /** | ||
| * Most of the use of `document` in Angular is from within the DI system so it is possible to simply | ||
| * inject the `DOCUMENT` token and are done. | ||
|
|
@@ -47,10 +49,15 @@ export function getDocument(): Document { | |
| } else if (typeof document !== 'undefined') { | ||
| return document; | ||
| } | ||
|
|
||
| throw new RuntimeError( | ||
| RuntimeErrorCode.MISSING_DOCUMENT, | ||
| (typeof ngDevMode === 'undefined' || ngDevMode) && | ||
| `The document object is not available in this context. Make sure the DOCUMENT injection token is provided.`); | ||
|
|
||
| // No "document" can be found. This should only happen if we are running ivy outside Angular and | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: maybe move the comment before the throw. |
||
| // the current platform is not a browser. Since this is not a supported scenario at the moment | ||
| // this should not happen in Angular apps. | ||
| // Once we support running ivy outside of Angular we will need to publish `setDocument()` as a | ||
| // public API. Meanwhile we just return `undefined` and let the application fail. | ||
| return undefined!; | ||
| // public API. | ||
| } | ||
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.