-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
fix(common): server-side rendering error when using in-memory scrolling #53683
Conversation
Shouldn't actually |
In that case we would have to provide a noop implementation of the class. The current class already has all the necessary checks in place, the only missing one was in the factory. |
@crisbeto, I don't quite see the necessity for creating a noop implementation. Since angular/packages/router/src/provide_router.ts Line 211 in d315e2c
Therefore, the following code should be adequate. The advantage here is that it avoids the creation and subscription to unused router events and can also contribute to better future-proofing, preventing potential regressions if a feature isn't utilized in SSR. const providers = [{
provide: ROUTER_SCROLLER,
useFactory: () => {
+ const platformId = inject(PLATFORM_ID);
+ if (!isPlatformBrowser(platformId)) {
+ return null;
+ }
+
const viewportScroller = inject(ViewportScroller);
const zone = inject(NgZone);
const transitions = inject(NavigationTransitions);
const urlSerializer = inject(UrlSerializer);
return new RouterScroller(urlSerializer, transitions, viewportScroller, zone, options);
},
}]; I'm not strongly attached to this suggestion, but I lean towards not enabling unnecessary features. |
My concern was that this is still going to error if somebody tries to inject |
ee1b89b
to
dbc8a41
Compare
Fixes that the `BrowserViewportScroller` was throwing an error during server-side rendering because it was accessing `window` directly. Also removes some assertions that aren't necessary anymore. Fixes angular#53682.
dbc8a41
to
d7c5769
Compare
This PR was merged into the repository by commit dd052dc. |
…ng (angular#53683) Fixes that the `BrowserViewportScroller` was throwing an error during server-side rendering because it was accessing `window` directly. Also removes some assertions that aren't necessary anymore. Fixes angular#53682. PR Close angular#53683
…ng (angular#53683) Fixes that the `BrowserViewportScroller` was throwing an error during server-side rendering because it was accessing `window` directly. Also removes some assertions that aren't necessary anymore. Fixes angular#53682. PR Close angular#53683
…ng (angular#53683) Fixes that the `BrowserViewportScroller` was throwing an error during server-side rendering because it was accessing `window` directly. Also removes some assertions that aren't necessary anymore. Fixes angular#53682. PR Close angular#53683
…ng (angular#53683) Fixes that the `BrowserViewportScroller` was throwing an error during server-side rendering because it was accessing `window` directly. Also removes some assertions that aren't necessary anymore. Fixes angular#53682. PR Close angular#53683
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
Fixes that the
BrowserViewportScroller
was throwing an error during server-side rendering because it was accessingwindow
directly. Also removes some assertions that aren't necessary anymore.Fixes #53682.