-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
NUX: Prevent duplicate DotTips from appearing #8642
Conversation
When there are multiple instances of `DotTip` that reference the same tip identifier, only show the first instance that was mounted.
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.
Looks good - I added a few comments, but they're optional changes apart from the typo.
Let me know if I misunderstood the code.
@@ -13,6 +13,43 @@ export function triggerGuide( tipIds ) { | |||
}; | |||
} | |||
|
|||
/** | |||
* Returns an action object that, when dispathed, associates an instance of the |
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.
minor typo here - dispathed -> dispatched
case 'REGISTER_TIP_INSTANCE': | ||
return { | ||
...state, | ||
[ action.tipId ]: union( state[ action.tipId ] || [], [ action.instanceId ] ), |
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.
Found this quite a hard line to read initially. I wonder if this would be more succinct? I think they do the same thing.
uniq( [ ...state[ action.tipId ], action.instanceId ] )
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.
We need to handle the case where state[ action.tipId ]
is undefined
.
uniq( [ ...state[ action.tipId ] || [], action.instanceId ] )
Maybe I'll just use a temporary variable.
const existingInstanceIds = state[ action.tipId ] || [];
uniq( [ ...existingInstanceIds, action.instanceId ] )
return false; | ||
} | ||
|
||
if ( instanceId ) { | ||
const [ firstInstanceId ] = state.tipInstanceIds[ tipId ] || []; |
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.
Was wondering - if we only use the first instance Id, do the others need to be stored in tipInstanceIds? Potentially the value of tipInstanceIds[ tipId ] could just be the instance Id of the first instance of that tip, instead of an array of all the tips. Maybe renamed to tipActiveInstanceId
or something
There might be another use case that I'm missing, though.
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.
The problem is that it doesn't handle the case where the first/active instance is unmounted because of e.g. a block removal. When this happens, the tip should move to the next available instance. You actually encounter this in the reproduction steps for the bug above, because the first/active DotTip
is unmounted when you insert the Columns block.
It's a pretty bizarre use-case, I'll admit. Hoping that we can make this all unnecessary either through #8050 or by otherwise iterating on these tips. Tammie and I have been working through some ideas on what to do with NUX...
We want to do 3.5 release today. I merged this PR. @noisysocks please open follow up and address the comments. At least the typo one 😄 |
This reverts commit 09dc71c.
Description
Fixes #8285.
When there are multiple instances of
DotTip
that reference the same tip identifier, only show the first instance that was mounted.I've done this by introducing the concept of "registration". When a
<DotTip id="foo">
instance mounts, it registers itself as being associated with the "foo" tip. When it unmounts, the registration is removed. Only the first instance to have registered itself for any given tip will be made visible.How has this been tested?
Screenshots