Skip to content

Commit

Permalink
chore(xplat): Update canUseDOM to be aware of ReactNative (#30872)
Browse files Browse the repository at this point in the history
  • Loading branch information
behowell authored Mar 26, 2024
1 parent 010acf5 commit 9a63a21
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "none",
"comment": "Update api.md file from TypeScript 5 changes",
"packageName": "@fluentui/react-accordion",
"email": "[email protected]",
"dependentChangeType": "none"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "chore(xplat): Update canUseDOM to be aware of ReactNative",
"packageName": "@fluentui/react-utilities",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@
"dependencies": {
"@fluentui/react-shared-contexts": "^9.15.2",
"@fluentui/react-theme": "^9.1.19",
"@fluentui/react-utilities": "^9.18.5",
"@griffel/core": "^1.14.1",
"@griffel/react": "^1.5.14",
"@swc/helpers": "^0.5.1",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export { shorthands } from './styling/shorthands';
export { isReactNative } from './utilities/isReactNative';

// re-export some griffel types to have fluent use the griffel adapter instead of griffel directly
export { useRenderer_unstable, TextDirectionProvider } from '@griffel/react';
export { makeStyles as makeStylesCore } from '@griffel/core';
export { TextDirectionProvider, useRenderer_unstable } from '@griffel/react';
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
} from '@fluentui/react-shared-contexts';
import type { FluentProviderContextValues, FluentProviderState, FluentProviderSlots } from './FluentProvider.types';
import { IconDirectionContextProvider } from '@fluentui/react-icons';
import { isReactNative, XPlatProvider } from '@fluentui/react-platform-adapter-preview';
import { XPlatProvider } from '@fluentui/react-platform-adapter-preview';

/**
* Render the final JSX of FluentProvider
Expand Down Expand Up @@ -41,7 +41,7 @@ export const renderFluentProvider_unstable = (
<IconDirectionContextProvider value={contextValues.iconDirection}>
<OverridesProvider value={contextValues.overrides_unstable}>
<state.root>
{canUseDOM() || isReactNative ? null : (
{canUseDOM() ? null : (
<style
// Using dangerous HTML because react can escape characters
// which can lead to invalid CSS.
Expand Down
1 change: 1 addition & 0 deletions packages/react-components/react-utilities/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"dependencies": {
"@fluentui/keyboard-keys": "^9.0.7",
"@fluentui/react-platform-adapter-preview": "^0.0.0",
"@fluentui/react-shared-contexts": "^9.15.2",
"@swc/helpers": "^0.5.1"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { isReactNative } from '@fluentui/react-platform-adapter-preview';

/**
* Verifies if an application can use DOM.
*/
export function canUseDOM(): boolean {
return (
// eslint-disable-next-line deprecation/deprecation, no-restricted-globals
typeof window !== 'undefined' && !!(window.document && window.document.createElement)
(typeof window !== 'undefined' && !!(window.document && window.document.createElement)) || isReactNative
);
}

0 comments on commit 9a63a21

Please sign in to comment.