Skip to content

Commit 96a23c1

Browse files
giuseppegnecolas
authored andcommitted
[fix] StyleSheet hydration with single quotes in attribute selectors
Edge uses single quotes for attribute selectors. Fix necolas#1317 Close necolas#1415
1 parent ebbade3 commit 96a23c1

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

packages/react-native-web/src/exports/StyleSheet/__tests__/createOrderedCSSStyleSheet-test.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,25 @@ describe('createOrderedCSSStyleSheet', () => {
8686
const clientSheet = createOrderedCSSStyleSheet(element.sheet);
8787
expect(clientSheet.getTextContent()).toMatchSnapshot();
8888
});
89+
90+
test('works when the group marker is in single quotes', () => {
91+
// Setup SSR CSS
92+
const serverSheet = createOrderedCSSStyleSheet();
93+
serverSheet.insert('.a { color: red }', 0);
94+
serverSheet.insert('.b { color: red }', 1);
95+
const textContent = serverSheet.getTextContent().replace(/"/g, "'");
96+
97+
// Add SSR CSS to client style sheet
98+
element.appendChild(document.createTextNode(textContent));
99+
const clientSheet = createOrderedCSSStyleSheet(element.sheet);
100+
clientSheet.insert('.c { color: red }', 0);
101+
expect(clientSheet.getTextContent()).toMatchInlineSnapshot(`
102+
"[stylesheet-group='0'] {}
103+
.a {color: red;}
104+
.c { color: red }
105+
[stylesheet-group='1'] {}
106+
.b {color: red;}"
107+
`);
108+
});
89109
});
90110
});

packages/react-native-web/src/exports/StyleSheet/createOrderedCSSStyleSheet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ function encodeGroupRule(group) {
143143
}
144144

145145
function decodeGroupRule(cssRule) {
146-
return Number(cssRule.selectorText.split('"')[1]);
146+
return Number(cssRule.selectorText.split(/["']/)[1]);
147147
}
148148

149149
function getOrderedGroups(obj: { [key: number]: any }) {

0 commit comments

Comments
 (0)