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: access document only in browser #15

Merged
merged 1 commit into from
Apr 16, 2024
Merged

Conversation

marcjulian
Copy link
Contributor

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Documentation content changes
  • Other... Please describe:

What is the current behavior?

Error in sonner toast while starting in SSR application:

ReferenceError: document is not defined
    at _NgxSonnerToaster (/Users/m/Dev/me/paddlingspots/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]/node_modules/ngx-sonner/fesm2022/ngx-sonner.mjs:1393:5)
    at SwipeStateTypes (/Users/m/Dev/me/paddlingspots/node_modules/.pnpm/[email protected]_@[email protected]_@[email protected]/node_modules/ngx-sonner/fesm2022/ngx-sonner.mjs:1458:14)
    at getNodeInjectable (/Users/m/Dev/me/paddlingspots/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@angular/core/fesm2022/core.mjs:5984:44)
    at instantiateAllDirectives (/Users/m/Dev/me/paddlingspots/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@angular/core/fesm2022/core.mjs:11907:27)
    at createDirectivesInstances (/Users/m/Dev/me/paddlingspots/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@angular/core/fesm2022/core.mjs:11306:5)
    at ɵɵelementStart (/Users/m/Dev/me/paddlingspots/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@angular/core/fesm2022/core.mjs:23014:9)
    at Module.ɵɵelement (/Users/m/Dev/me/paddlingspots/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@angular/core/fesm2022/core.mjs:23072:5)
    at getActiveTransaction (/Users/m/Dev/me/paddlingspots/libs/ui/ui-sonner-helm/src/lib/hlm-toaster.component.ts:15:5)
    at executeTemplate (/Users/m/Dev/me/paddlingspots/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@angular/core/fesm2022/core.mjs:11268:9)
    at renderView (/Users/m/Dev/me/paddlingspots/node_modules/.pnpm/@[email protected][email protected][email protected]/node_modules/@angular/core/fesm2022/core.mjs:12470:13)

What is the new behavior?

Document is only accessed on the browser.

Does this PR introduce a breaking change?

  • Yes
  • No

Other information

An alternative would be to use the new lifecycle hook afterRender/afterNextRender to perform browser specific code (https://angular.dev/guide/ssr#authoring-server-compatible-components).

Copy link
Owner

@tutkli tutkli left a comment

Choose a reason for hiding this comment

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

Thanks @marcjulian ! I prefer to keep isPlatformBrowser because we also need in the ngOnDestroy method.

@tutkli tutkli merged commit 308a56a into tutkli:master Apr 16, 2024
2 checks passed
@marcjulian marcjulian deleted the fix/ssr branch April 16, 2024 08:41
tutkli pushed a commit that referenced this pull request Apr 16, 2024
## [0.4.2](v0.4.1...v0.4.2) (2024-04-16)

### Bug Fixes

* access document only in browser ([#15](#15)) ([308a56a](308a56a))
@tutkli
Copy link
Owner

tutkli commented Apr 16, 2024

🎉 This PR is included in version 0.4.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants