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

fix(cdk/listbox): improve SSR compatibility by adding an _isBrowser check before calling _setPreviousActiveOptionAsActiveOptionOnWindowBlur #28746

Merged
merged 2 commits into from
Mar 21, 2024

Conversation

james-albanese
Copy link
Contributor

This PR addresses the ReferenceError: window is not defined error that gets thrown when the CDK Listbox is rendered on the server.

The _setPreviousActiveOptionAsActiveOptionOnWindowBlur method in the CdkListbox class uses RxJS' fromEvent with window as its target. This is problematic when the application is being rendered on the server, since _setPreviousActiveOptionAsActiveOptionOnWindowBlur is called in the constructor.

The solution is to add a simple _isBrowser property that leverages the Platform API and a check in the constructor before calling _setPreviousActiveOptionAsActiveOptionOnWindowBlur.

@james-albanese james-albanese changed the title Improve SSR compatibility by adding an _isBrowser check before calling _setPreviousActiveOptionAsActiveOptionOnWindowBlur fix(cdk/listbox): improve SSR compatibility by adding an _isBrowser check before calling _setPreviousActiveOptionAsActiveOptionOnWindowBlur Mar 19, 2024
Copy link
Member

@crisbeto crisbeto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Mar 21, 2024
@crisbeto crisbeto self-assigned this Mar 21, 2024
@crisbeto crisbeto merged commit 9c4e451 into angular:main Mar 21, 2024
24 of 26 checks passed
crisbeto pushed a commit that referenced this pull request Mar 21, 2024
…heck before calling _setPreviousActiveOptionAsActiveOptionOnWindowBlur (#28746)

* Add _isBrowser check before calling _setPreviousActiveOptionAsActiveOptionOnWindowBlur

* add basic example for cdk listbox

(cherry picked from commit 9c4e451)
@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 21, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants