Skip to content
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

fix: Placeholder error handling for inserting CSS rules #1300

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

matthewlipski
Copy link
Collaborator

@matthewlipski matthewlipski commented Dec 3, 2024

The placeholder extension inserts CSS rules which use pseudo-selectors, specifically :has, :only-child, and :before. These are not supported in older browsers, for example the :has selector only works in versions of Firefox after 120.

This PR mitigates the issue by wrapping insertion of the CSS rules in a try/catch block, so that if the CSS selectors aren't supported, the placeholders won't be visible but the error thrown won't break other things in the editor.

Closes #1286

…wsers may not support pseudo-element selectors
Copy link

vercel bot commented Dec 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
blocknote ✅ Ready (Inspect) Visit Preview Dec 3, 2024 1:35pm
blocknote-website ✅ Ready (Inspect) Visit Preview Dec 3, 2024 1:35pm

Copy link
Collaborator

@YousefED YousefED left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. The editor functions fine I suppose, except that placeholders won't be shown?

@matthewlipski
Copy link
Collaborator Author

matthewlipski commented Dec 3, 2024

Looks good. The editor functions fine I suppose, except that placeholders won't be shown?

Yep that's right, I'll update the description to make that more clear

@matthewlipski matthewlipski merged commit a2b076a into main Dec 3, 2024
5 checks passed
@Ambercssa
Copy link

const getBaseSelector = (additionalSelectors = "") => {
if (supportsHasPseudo()) {
return .bn-block-content${additionalSelectors} .bn-inline-content:has(> .ProseMirror-trailingBreak:only-child):before;
} else {
const blocks = document.querySelectorAll(.bn-block-content${additionalSelectors} .bn-inline-content > .ProseMirror-trailingBreak)
if (blocks && blocks.length === 1) {
return .bn-block-content${additionalSelectors} .bn-inline-content:before;
} else {
return null
}
}
};
const supportsHasPseudo = (): boolean => {
try {
document.querySelector(":has(*)");
return true;
} catch {
return false;
}
};

 I tried to modify it, and it seems to work too

@Ambercssa
Copy link

This method will not prevent placeholders from displaying

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Firefox 115, the toolbar doesn't display
3 participants