Skip to content
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

bug(datepicker/mat-calendar): ERROR ReferenceError: window is not defined #26729

Closed
1 task
evheniyrz opened this issue Mar 6, 2023 · 4 comments · Fixed by #26742
Closed
1 task

bug(datepicker/mat-calendar): ERROR ReferenceError: window is not defined #26729

evheniyrz opened this issue Mar 6, 2023 · 4 comments · Fixed by #26742
Assignees
Labels
area: material/datepicker P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@evheniyrz
Copy link

evheniyrz commented Mar 6, 2023

Is this a regression?

  • Yes, this behavior used to work in the previous version

The previous version in which this bug was not present was

13.x

Description

I use the date picker in calendar mode in the sidebar on the main page. the component is initialized when the application is loaded.
After upgrading from version 13.x to 14.x and after to 15.x I get an error in the console. But the application starts up and the calendar works

<mat-calendar
  (selectedChange)="dateChange($event)"
  [(selected)]="selectedDate"
  [dateClass]="dateStyleFn"
  class="app-calendar"></mat-calendar>

Reproduction

Steps to reproduce:

  1. Angular Universal (SSR) project
  2. npm run dev:ssr

Expected Behavior

no error

Actual Behavior

ERROR ReferenceError: window is not defined
at apply (./node_modules/@angular/material/fesm2020/datepicker.mjs:289:13)
at invoke (./node_modules/zone.js/dist/zone-node.js:400:30)
at run (./node_modules/zone.js/dist/zone-node.js:160:47)
at runOutsideAngular (./node_modules/@angular/core/fesm2020/core.mjs:24137:28)
at constructor (./node_modules/@angular/material/fesm2020/datepicker.mjs:280:17)
at factory (./node_modules/@angular/material/fesm2020/datepicker.mjs:492:21)
at getNodeInjectable (./node_modules/@angular/core/fesm2020/core.mjs:3484:44)
at instantiateAllDirectives (./node_modules/@angular/core/fesm2020/core.mjs:11038:27)
at createDirectivesInstances (./node_modules/@angular/core/fesm2020/core.mjs:10511:5)
at Module.ɵɵelementStart (./node_modules/@angular/core/fesm2020/core.mjs:13641:9)

Environment

  • Angular: ~15.2.1
  • CDK/Material: ^15.2.1
  • Browser(s): Crome
  • Operating System (e.g. Windows, macOS, Ubuntu): Windows 10 64-bit
@evheniyrz evheniyrz added the needs triage This issue needs to be triaged by the team label Mar 6, 2023
@crisbeto crisbeto self-assigned this Mar 7, 2023
@crisbeto crisbeto added P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent area: material/datepicker and removed needs triage This issue needs to be triaged by the team labels Mar 7, 2023
crisbeto added a commit to crisbeto/material2 that referenced this issue Mar 7, 2023
Fixes that the datepicker was referring to the `window` which throws an error during server-side rendering.

Fixes angular#26729.
crisbeto added a commit that referenced this issue Mar 8, 2023
Fixes that the datepicker was referring to the `window` which throws an error during server-side rendering.

Fixes #26729.

(cherry picked from commit fbca2e9)
crisbeto added a commit that referenced this issue Mar 8, 2023
Fixes that the datepicker was referring to the `window` which throws an error during server-side rendering.

Fixes #26729.
@evheniyrz
Copy link
Author

@crisbeto Which version of material will this fix apply to?

@crisbeto
Copy link
Member

crisbeto commented Mar 8, 2023

It should be in 15.2.2.

@evheniyrz
Copy link
Author

Ok thanks

It should be in 15.2.2.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Apr 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area: material/datepicker P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants