-
Notifications
You must be signed in to change notification settings - Fork 65
feat: add validation into mergeClasses for makeResetStyles calls #260
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
Merged
layershifter
merged 2 commits into
microsoft:main
from
layershifter:feat/griffel-validation
Oct 26, 2022
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
change/@griffel-core-f18356ed-6d74-4218-a44d-df648ef511ac.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
| "comment": "feat: add validation into mergeClasses for makeResetStyles calls", | ||
| "packageName": "@griffel/core", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } |
7 changes: 7 additions & 0 deletions
7
change/@griffel-jest-serializer-d855a4d4-e4c6-4f70-a258-c22caa4992ea.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| { | ||
| "type": "patch", | ||
layershifter marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "comment": "feat: add support for makeResetStyles", | ||
| "packageName": "@griffel/jest-serializer", | ||
| "email": "[email protected]", | ||
| "dependentChangeType": "patch" | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,7 @@ | ||
| import { DEBUG_RESET_CLASSES } from './constants'; | ||
| import { resolveResetStyleRules } from './runtime/resolveResetStyleRules'; | ||
| import type { GriffelResetStyle, MakeStylesOptions } from './types'; | ||
|
|
||
| /** | ||
| * @internal | ||
| */ | ||
|
Comment on lines
-4
to
-6
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oops, a leftover from the time when it was unstable. |
||
| export function makeResetStyles(styles: GriffelResetStyle) { | ||
| const insertionCache: Record<string, boolean> = {}; | ||
|
|
||
|
|
@@ -28,7 +26,13 @@ export function makeResetStyles(styles: GriffelResetStyle) { | |
| insertionCache[rendererId] = true; | ||
| } | ||
|
|
||
| return isLTR ? ltrClassName : rtlClassName || ltrClassName; | ||
| const className = isLTR ? ltrClassName : rtlClassName || ltrClassName; | ||
|
|
||
| if (process.env.NODE_ENV !== 'production') { | ||
| DEBUG_RESET_CLASSES[className] = 1; | ||
| } | ||
|
|
||
| return className; | ||
| } | ||
|
|
||
| return computeClassName; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| import { DEFINITION_LOOKUP_TABLE, CSSClasses } from '@griffel/core'; | ||
| import { DEBUG_RESET_CLASSES, DEFINITION_LOOKUP_TABLE, CSSClasses } from '@griffel/core'; | ||
|
|
||
| export function print(val: unknown) { | ||
| /** | ||
|
|
@@ -17,6 +17,12 @@ export function print(val: unknown) { | |
|
|
||
| while ((result = regex.exec(_val))) { | ||
| const [name] = result; | ||
|
|
||
| if (DEBUG_RESET_CLASSES[name]) { | ||
| regexParts.push(name); | ||
| continue; | ||
| } | ||
|
|
||
| const [definitions] = DEFINITION_LOOKUP_TABLE[name]; | ||
|
|
||
| /** | ||
|
|
@@ -34,7 +40,7 @@ export function print(val: unknown) { | |
| /** | ||
| * form parts of regular expression and removes collected classNames from string | ||
| * @example | ||
| * regex = /r?(f16th3vw|frdkuqy0|fat0sn40|fjseox00)/ | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't use |
||
| * regex = /f16th3vw|frdkuqy0|fat0sn40|fjseox00/ | ||
| */ | ||
| const valStrippedClassNames = _val.replace(new RegExp(regexParts.join('|'), 'g'), '').trim(); | ||
|
|
||
|
|
@@ -61,7 +67,7 @@ export function test(val: unknown) { | |
| * lookupRegex() // /(__1qdh4ig)/g | ||
| */ | ||
| function lookupRegex(): RegExp | undefined { | ||
| const definitionKeys = Object.keys(DEFINITION_LOOKUP_TABLE); | ||
| const definitionKeys = Object.keys({ ...DEFINITION_LOOKUP_TABLE, ...DEBUG_RESET_CLASSES }); | ||
|
|
||
| if (definitionKeys.length) { | ||
| return new RegExp(`${definitionKeys.join('|')}`, 'g'); | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
shouldn't this be a
minor?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.
Yup