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

bug(parser): fix parsing of multiline class attribute value (#4242) #4243

Closed
wants to merge 1 commit into from

Conversation

kreativ-los
Copy link

Fixes #4242

@Conduitry
Copy link
Member

Conduitry commented Jan 13, 2020

Is the issue that this is fixing just that the scoped .foo styles aren't recognized as applying to the element with the CSS class containing foo and newlines? I didn't see any other problems in #4242. I don't think removing this whitespace during parsing is the right solution, because the user might want that whitespace for certain attributes. As far as I can tell, what needs to be fixed here is how the compiler identifies which selectors might apply to which elements.

edit: For a concrete example, if someone had a title attribute on an element which contained newlines, we'd need to preserve those. We don't want to change how we're parsing attributes.

@ghost
Copy link

ghost commented Jan 13, 2020

Yeah, I agree with @Conduitry.
I think this pull request will strip that type of whitespace off of all attributes, not just class.

Normal DOM matching will strip for the purpose of matching selectors, but retain it for the purpose of rendering the class name. We need to build an analog of DOMTokenList or at least implement the whitespace rules, not change the parsing of the attributes itself.

The bug itself is still a great catch since it works in traditional pages and not with scoped styles.

@tanhauhau
Copy link
Member

@kreativ-los https://github.com/sveltejs/svelte/blob/master/src/compiler/compile/css/Selector.ts#L211 is where we match the dom nodes with the class name, you can figure out why multiline causes it to not match.

@kreativ-los
Copy link
Author

Thanks for your feedback :) I will give @tanhauhau answer a look and try to fix it in the compiler. Will this also fix the "Unused CSS selector" linting error, or is this done separately?

@Conduitry
Copy link
Member

That should take care of all of it. The reason for that warning is because the compiler doesn't see that selector as applying to that element. Thanks!

@Conduitry Conduitry closed this Jan 14, 2020
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.

Multiline class attribute value breaks svelte
3 participants