fix: Fix finding inputs with IDs containing spaces #3852
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.
Fixes #2799
The key issue in #2799 is that the input message handler uses
"#" + message[i].id
to compose the selector used to find the appropriate input. While it'd be reasonable to establish that input IDs should not contain spaces, we don't have any upstream checks and they clearly work in most cases.This PR updates the update input message handler and the tab insert/remove logic to switch between a
#${id}
and[id="${id}"]
selector depending on whether the ID contains spaces. The attribute selector is a tad slower, which is why we first check for spaces and use the#
based selector if we can.If we do detect spaces, we throw a console warning so that users can track down the offending input or tabset and fix it.
I've only updated message handling logic where we were using the
"#" + id
pattern, in which case switching the selector is safe. I also think this is a safe approach considering that in cases where IDs without spaces are strictly required we should throw from the input constructor or warn from the update helper function; in both cases users should alert us to broken behavior.Reprex App
Here's a very small app that demonstrates the change in behavior using
updateSliderInput()
.