Skip to content

Commit 7037100

Browse files
committed
Fix css classnames plugin to work with older browsers
1 parent 25e83c6 commit 7037100

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

.changeset/orange-parts-try.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@plexinc/react-native-lightning": patch
3+
---
4+
5+
Fix css classnames plugin to work with older browsers

packages/react-native-lightning/src/plugins/cssClassNameTransformPlugin.ts

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { Plugin } from '@plexinc/react-lightning';
2-
import { StyleSheet } from 'react-native-web';
32
// Necessary for the declaration merging to work below, since we don't import
43
// the `react-native-web` typings.
54
import '../types/react-native-web.d.ts';
@@ -15,9 +14,13 @@ function camelize(text: string) {
1514
}
1615

1716
export const cssClassNameTransformPlugin = (): Plugin => {
18-
const sheet = new CSSStyleSheet();
17+
const sheet = Array.from(document.styleSheets).find((s) => {
18+
const node = s.ownerNode;
19+
20+
return node && 'id' in node ? node.id === 'react-native-stylesheet' : null;
21+
}) ?? { cssRules: [] };
22+
1923
const cache: Record<string, Record<string, string>> = {};
20-
let currentCssText = '';
2124

2225
function parseStyle(cssText: string) {
2326
if (!cache[cssText]) {
@@ -43,13 +46,6 @@ export const cssClassNameTransformPlugin = (): Plugin => {
4346
return props;
4447
}
4548

46-
const newCssText = StyleSheet.getSheet().textContent;
47-
48-
if (newCssText !== currentCssText) {
49-
sheet.replaceSync(newCssText);
50-
currentCssText = newCssText;
51-
}
52-
5349
const { className, style, ...otherProps } = props;
5450
let finalStyle: typeof style = {};
5551

0 commit comments

Comments
 (0)