-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 ignoreFlag not works bug #2751
Conversation
🦋 Changeset detectedLatest commit: b82bcee The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work! This looks good to me, but let's wait for @Andarist's approval.
Can you add a changeset to record this patch-level change to @emotion/cache
?
Edit: I noticed that CI is failing with
@emotion/cache "@babel/runtime/helpers/createForOfIteratorHelperLoose" is imported by "src/stylis-plugins.js" but the package is not specified in dependencies or peerDependencies
This is caused by the for..of
loop you added. We still technically support IE 11, so we have to stick to old-school JS in some places. Can you refactor the for..of
to a classic for
loop or a .forEach()
?
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit b82bcee:
|
Codecov Report
|
@srmagura
Add a changeset commit!
I used classic for loop because it is returnable! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from making the changeset more descriptive, this looks good to me. The changesets end up in our release notes so they need to clearly explain what was changed.
Co-authored-by: Sam Magura <srmagura@gmail.com>
@Andarist How is this going? |
@@ -52,6 +66,20 @@ exports[`unsafe pseudo classes does not warn when using with flag: /* emotion-di | |||
/> | |||
`; | |||
|
|||
exports[`unsafe pseudo classes does not warn when using with flag: /* emotion-disable-server-rendering-unsafe-selector-warning-please-do-not-use-this-the-warning-exists-for-a-reason */ ":first-child :nth-child(3) /* [flag] */" in a style multiple selectors 1`] = ` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on the [flag]
here it seems that the original intention was to replace that long string in test titles to aid the readability. There is .replace
call somewhere that perhaps doesn't replace all occurrences of that flag in the input string - could you check if this assumption is correct and if we could fix this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, actually the full flag is part of the describe
's title and is literally passed in there:
describe(`does not warn when using with flag: ${ignoreSsrFlag}`, () => { |
So we don't need to change anything here and that was the original intention (perhaps we could change it separately, but it doesn't matter)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is
.replace
call somewhere that perhaps doesn't replace all occurrences of that flag in the input string
Replaced by /* [flag] */
here.
emotion/packages/react/__tests__/warnings.js
Lines 117 to 120 in d39379c
it(`"${pseudoClass.replace( | |
/\/\* \S+ \*\//g, | |
'/* [flag] */' | |
)}" in a style ${type}`, () => { |
Do you need to modify or add test cases?
packages/cache/src/stylis-plugins.js
Outdated
for (let i = 0; i < children.length; i++) { | ||
const element = children[i] | ||
if (element && isIgnoringComment(last(element.children))) { | ||
return | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you describe the change? What was the assumption of the previous code? How the fixed case is different and why it didn't work with the previous logic? What was the thought process behind the introduced change? I would appreciate if you could show the AST layouts of different cases so it would be easier to reason about this fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the previous logic, only the first ignoreFlag in a style worked.
Therefore, CI passed, but if there were multiple styles and the second or later style used unsafe pseudo classes (ex. :first-child
), an error would be displayed even if the ignoreFlag was given.
Could you check if this would fix the recently reported issue: #2763 ? |
@Andarist deployed site: https://kyoncy.github.io/emotion-test/ |
@kyoncy thanks for taking a look. I've pushed out some commits to make this comment detection more strict - we should be able to land this soon. I will just wait a couple of days to give a chance to other maintainers to review this |
Hi! I know this is not a fully valid bug report. Still it seems that updating from v11.10.1 to v11.10.2 breaks in our application. I receive the error: |
Seems to be related to: var isIgnoringComment = function isIgnoringComment(element) {
return element.type === 'comm' && element.children.indexOf(ignoreFlag) > -1;
}; which can be fixed using: var isIgnoringComment = function isIgnoringComment(element) {
return element && element.type === 'comm' && element.children.indexOf(ignoreFlag) > -1;
}; |
The code involved producing the issue is:
I guess it's related to the multiple usage of
the issue disappears. |
Thank you for the report - I've already merged in the fix for this and gonna release a new version in a second. |
What:
Fix #2478
Why:
To ignore unsafe selector warning.
How:
The current implementation only compared the previous element, so all elements are now compared.
Checklist: