-
Notifications
You must be signed in to change notification settings - Fork 16
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
Ignore property set if document is not present (SSR). #17
Comments
I don't have any experience in using Capacitor in an SSR environment. On this line the |
In my opinion, yes. SSR loads only js scripts for web (Node JS server) and not related code of Android and iOS. Other extensions for React, Vue, etc. that uses |
But it's still important to call |
If you want to still call function setProperty(position: 'top' | 'left' | 'bottom' | 'right') {
if (typeof window === 'undefined') return
document /* is window.document */
.querySelector<HTMLElement>(':root')
?.style.setProperty(
`--safe-area-inset-${position}`,
`max(env(safe-area-inset-${position}), 0px)`,
);
} or function setProperty(position: 'top' | 'left' | 'bottom' | 'right') {
if (typeof window !== 'undefined' && 'document' in window) {
document /* is window.document */
.querySelector<HTMLElement>(':root')
?.style.setProperty(
`--safe-area-inset-${position}`,
`max(env(safe-area-inset-${position}), 0px)`,
);
}
} |
Yeah, I can implement such a check, I understand that. But it would only prevent the error being thrown. It wouldn't solve the actual problem. The actual problem is that those fallback CSS variables should be injected at some point in time - the earlier the better. Since Capacitor in combination with SSR is a not so usual use case, I have no idea where to inject the variables instead. I don't think there is a universal hydration method or document ready listener |
I understand, but it is not possible to set this CSS variables on SSR (server side) because there is no :root {
--safe-area-inset-bottom: 0;
--safe-area-inset-left: 0;
--safe-area-inset-right: 0;
--safe-area-inset-top: 0;
} |
Opened a PR that should solve your problem #19 By the way, you probably shouldn't be doing this: :root {
--safe-area-inset-bottom: 0;
} Because on iOS and web, you now lost the fallback to the natively supported :root {
--safe-area-inset-bottom: max(env(safe-area-inset-bottom), 0px);
} |
Describe the bug
If using in an SSR environment
document
(/index.ts#L10) is not present. So, the plug-in should ignoresetProperty
ifdocument
is not present.To Reproduce
Steps to reproduce the behavior:
@capacitor-community/safe-area
capacitor.config.ts
import '@capacitor-community/safe-area'
Expected behavior
It should work for web in a SSR environment.
The text was updated successfully, but these errors were encountered: