Skip to content

Commit a2b076a

Browse files
Added error handling for inserting placeholder CSS rules as older browsers may not support pseudo-element selectors (#1300)
1 parent 8bcf748 commit a2b076a

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

packages/core/src/extensions/Placeholder/PlaceholderPlugin.ts

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,30 @@ export class PlaceholderPlugin {
4848
for (const [blockType, placeholder] of Object.entries(placeholders)) {
4949
const mustBeFocused = blockType === "default";
5050

51-
styleSheet.insertRule(
52-
`${getSelector(
53-
blockType,
54-
mustBeFocused
55-
)}{ content: ${JSON.stringify(placeholder)}; }`
56-
);
57-
58-
// For some reason, the placeholders which show when the block is focused
59-
// take priority over ones which show depending on block type, so we need
60-
// to make sure the block specific ones are also used when the block is
61-
// focused.
62-
if (!mustBeFocused) {
51+
try {
6352
styleSheet.insertRule(
64-
`${getSelector(blockType, true)}{ content: ${JSON.stringify(
65-
placeholder
66-
)}; }`
53+
`${getSelector(
54+
blockType,
55+
mustBeFocused
56+
)} { content: ${JSON.stringify(placeholder)}; }`
57+
);
58+
59+
// For some reason, the placeholders which show when the block is focused
60+
// take priority over ones which show depending on block type, so we need
61+
// to make sure the block specific ones are also used when the block is
62+
// focused.
63+
if (!mustBeFocused) {
64+
styleSheet.insertRule(
65+
`${getSelector(blockType, true)} { content: ${JSON.stringify(
66+
placeholder
67+
)}; }`
68+
);
69+
}
70+
} catch (e) {
71+
// eslint-disable-next-line no-console
72+
console.warn(
73+
`Failed to insert placeholder CSS rule - this is likely due to the browser not supporting certain CSS pseudo-element selectors (:has, :only-child:, or :before)`,
74+
e
6775
);
6876
}
6977
}

0 commit comments

Comments
 (0)