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.
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 this reference for functions #38725
Fix this reference for functions #38725
Changes from all commits
9148528
dcf21d6
f2411f7
52b3d48
0793b5d
8c85eb7
bf47ca9
407305c
fde01d9
878b596
3dc6732
d828f67
03075be
a1a57a0
051f5cd
2b2ca8a
66ed889
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 suppose it is better to change only this, as it is count as a regression, and add a test, instead of messing all the rest calls
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.
This callsite doesn't actually matter, AFAICT. There are two calls where the
this
argument is important:_resolvePossibleFunction
injs/src/tooltip.js
execute(this._config.placement, ...)
in_createPopper
injs/src/tooltip.js
I can update those two call sites to use the
typeof arg === 'function' ...
pattern if you'd prefer that I avoid changingexecute
?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'm in the process of understanding what was there before and what's changing in this PR. It's a bit challenging to think about all the use cases, so I hope you won't mind if my remarks or questions are not yet precise or accurate.
If we don't think about the entire context of this PR and focus on this
Util.execute
function only, I'm not that comfortable with an extra first parameter that seems useless. Considering this function in isolation, we would probably expect it to work like this:Util.execute(<function reference>)
orUtil.execute(<function reference>, [])
when there's no argsUtil.execute(<function reference>, [<arg 1>]
Util.execute(<function reference>, [<arg 1>, <arg 2>]
I'm not saying it doesn't have impacts or that it's not technically feasible, but in terms of pure interface design, don't you think this
undefined
first argument in the list should be removed?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 think my rationale for doing it this way is that the
args
array directly mirrors howFunction.prototype.call
works, where the first argument isthis
and the remaining ones are the arguments.I'm entirely happy to change the interface, e.g. by updating
Util.execute
to explicitly take a value to be used atthis
. For instance, we could updateUtil.execute
to look like this:Then, the test case you commented on here would look like this:
Of course, we could reorder the arguments, but I think putting it before the arguments (again to mirror
Function.prototype.call
) would make the most sense.It's also possible that
Util.execute
is simply the wrong thing to be using in the callbacks for tooltips. As mentioned in #38725 (comment), I'm happy to switch those callsites to essentially inline it instead: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 wasn't immediately clear to me, but now I see the value in mirroring
Function.prototype.call
as you suggested.With your explanation, I'd say that your version in this PR,
Util.execute(functionFoo, [undefined, 4, 5]);
is a better fit because it aligns more closely withFunction.prototype.call
.Yes it would.
I'm not the sole decision-maker here, but from my perspective as a non-JS expert, either approach could work. The initial idea with #36652 was to consolidate functionality and avoid repetitive
typeof arg === 'function'
checks. Thus, retainingexecute
seems reasonable if we want to maintain that approach.You've already done the work to keep
execute
, so given that I don't have a strong preference at the moment, I'll continue to review the use cases from this angle.Note: I'm currently trying to reach the JS maintainers to discuss how we can proceed and finalize this PR with their input and yours.
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 great! I'll be ready to chat with you or the other JS maintainers to find an approach that'll make everyone happy.
Just so it isn't overlooked, a main decision to make here is whether or not Bootstrap will continue calling these functions with the tooltip/popover/etc. as an explicit argument as well as the old behavior of setting
this
. If there's a desire to keep the accidentally-introduced new behavior, I'll add tests and update docs to reflect that.My 2 cents: let's support the new behavior as well.
this
feels like it might have been born from the jQuery era.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.
OK, so we got a regression where folks had to use a workaround. The basic principle of a fix is that when there's a new patch release (v5.3.x), folks can then remove their workaround so that it works like before.
Since we didn't release a patch promptly, this workaround might now be seen as a de facto part of the API. Even if it isn't officially recognized as such, we may decide not to inconvenience users who have relied on and adapted to this workaround for an extended period. Otherwise, they might perceive the new patch as a disruptive change/breaking change as well, if not retro-compatible. 🙃
Considering these factors, I'd say supporting both the old and the new behavior would ensure a seamless transition for everyone installing the patch version (and we might even consider later on deprecating the old behavior in a future major Bootstrap version, for example):
Yet, I'm wondering whether introducing the new behavior in the documentation should wait until v5.4.0. Even though the feature could be currently present but hidden, delaying its documentation could help us avoid unnecessary remarks and comments. Not entirely sure if this is the right strategy.
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.
Maybe a reasonable middle ground is to implement+test both but avoid documenting the "new" behavior until either a future minor/major release?
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.
Yeah, that was the idea I had in mind.
Implement + test both so that it works for all use cases (migrating from versions before the breaking change, but also supporting transparently workarounds that have been applied). It would give us some space if there are mistakes with the new implementation (as long as the old implementation is fixed and the previous doc still works).
Once we have ensured stability, we can document and present the "new" behavior as a minor feature in v5.4.
If this approach sounds reasonable and feasible to you and others involved in this PR, I suggest we proceed with this strategy in mind.
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 updated the implementation and tests in a1a57a0.