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

trim className before split to avoid empty className #86

Closed
wants to merge 1 commit into from

Conversation

1inus
Copy link

@1inus 1inus commented Feb 22, 2021

in function patchAttributes(dom, prev, cur), className like 'someClassName ' get an array contains empty element after split(' ') called. dom.classList.add(emptyString) will case an exception : Uncaught (in promise) DOMException: Failed to execute 'add' on 'DOMTokenList': The token provided must not be empty.

@marijnh
Copy link
Member

marijnh commented Feb 22, 2021

We're targeting platforms (specically IE11) that don't have trim. Maybe express this as a filter call after the split instead to avoid that?

@BrianHung
Copy link
Contributor

BrianHung commented Mar 15, 2021

MDN and caniuse says that String.prototype.trim has been supported since IE10.

Using .split(" ").filter(Boolean) is more compatible (with up to IE9) but prosemirror homepage says compatibility starts at IE11.

Edit: I initially made a PR (#89) to add trim() to both prevClass and curClass, but I realized another benefit of using a boolean filter is that it removes all trailing, leading, and inner white space while trim only removes trailing and leading.

@marijnh
Copy link
Member

marijnh commented Mar 16, 2021

Ah, I guess it's trimStart/trimEnd that aren't in IE11. Thanks for pointing that out. I agree the filter patch is nicer.

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.

3 participants