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.
I may be wrong here, but I think some incorrect types might be deceiving us here.
See this usage of
getStyledClassNameFromKey()
:gutenberg/packages/components/src/ui/context/context-connect.ts
Lines 94 to 106 in 8dee3e6
Seems like
namespace
could be an array? If that happens, this will crash, while_.kebabCase( [ 'test', 'x' ] )
will work just fine, returningtest-x
.This other use of
getStyledClassNameFromKey()
is in a similar situation like the one I reported here:gutenberg/packages/components/src/ui/context/use-context-system.js
Line 54 in cb10bcf
Since the namespace is declared by externally exposed API (
useContextSystem()
), theoretically, the namespace could betest1
and then one of them would yield atest1
class, and the other would yield atest-1
class. That would basically be an unexpected breaking change.I think to get around this, we need to make sure that the replacement function behaves exactly the same way when mixing letters, numbers and special characters.
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.
Thanks Marin! I'm currently working through your feedback. Regarding
namespace
is typed asstring
so if you try to pass an array tocontextConnect
you'd get a type error. I'm not exactly sure why the guard is still in place, it's probably a leftover from #31099 where theArray<string>|string
type was replaced withstring
. My assumption is we could remove it.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.
Sounds good for the array case. I'd suggest we remove it then, so we're intentional with our type approach here. Can be done in a separate PR, but I think it should be done before this one lands.
What do you think about this other difference that I mentioned? Reposting here for clarity:
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.
I had a quick look and it doesn't seem that neither
getStyledClassNameFromKey
noruseContextSystem()
are exported by the@wordpress/components
package (via thepackages/components/src/index.js
file).Maybe @sarayourfriend could help us to clarify any remaining doubts on this, since she worked extensively on the context system?
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.
I've manually audited the existing usages and I have no further concern. The use case I've mentioned does not occur, and it won't cause any regressions, so we should be safe to move forward.
The only suggestion I'd have before shipping this one would be removing the unnecessary array handling that we discussed above.
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.
I started looking into removing the array handling we talked about and found a few more things which might be worth addressing. I'm going to discuss those with @ciampo this week (as I don't fully understand a few parts of the components context system). Could we unblock this PR and make your suggestion a follow up @tyxla?
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.
Cool, a follow-up sounds good 👍 Thanks @flootr
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.
Happy to help if I can, but can you clarify what the question is?
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.
It's mostly about the naming of contexts in
useContextSystem()
and specifically, treating numbers. It was about whether if we calluseContextSystem( 'test-1' )
, we should expect to get a className oftest-1
ortest1
.I realize this might be coming from the original g2 implementation, in which case @sarayourfriend might not have the answer too.
I'm fine with making a decision here though, since
useContextSystem()
is still internal and uses no numbers in context names just yet. That's why I approved the 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.
Yup, I have no idea what the original intention is.
Excellent 😁