-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
fix: improve resolution of dashed prop names #3576
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
Conversation
This pull request is automatically built and testable in CodeSandbox. To see build info of the built libraries, click here or the icon next to each commit SHA. Latest deployment of this branch, based on commit 7c6680f:
|
What is an "unknown prop" in this case? |
Duplicate with #3573? If you write |
Is there some better way to solve this? |
Yes, you're exactly right! This PR addresses the same issue as #3573. Both PRs are trying to fix the problem where Feel free to close this PR if #3573 is the preferred approach, or let me know if there are any changes needed to align with the solution you have in mind. |
This is an awkward part of the codebase and so will necessitate awkward solutions. It is legal for keys to have dashes in them such as
Right now my thinking is we should have the following rules:
<mesh my--prop="value" /> // Apply to key my-prop
<mesh material-color--space /> // Apply to material['color-space']
// Or if that is too confusing to read something like this
<mesh _my-prop_="value" /> // Apply to key my-prop
I believe silent failures will lead to more confusion than it solves. Having a prop fail to set is breaking a contract with React and our deep path setting is brittle enough as it is. I don't want to encourage making it even more brittle! Our contract here is that we will set values on nested objects but you must guarantee React that those paths will be valid and unchanged. I am hesitant on adding an explicit escape just because it adds more rules and exceptions where we already have too many but I still think making those exceptions implicit will not be good. |
My personal opinion is that it's not advisable to solve this issue by defining specific rules. A better approach would be to simply ignore any key that isn't valid (ideally, throw a warning).
|
I agree with @acdzh's perspective here. Given React JSX's nature where any prop can be injected unexpectedly, it seems counterintuitive for a library to define its own whitelist of acceptable props. Currently, props without dashes are silently ignored when they don't match valid Three.js properties, and users aren't confused by this behavior. Having props with dashes behave consistently with this pattern would reduce user confusion and maintain a more predictable API surface. Rather than introducing custom rules and escape mechanisms, handling unknown props gracefully (whether they contain dashes or not) would provide a more robust and user-friendly experience. |
It is unfortunate that type safety suffers with prop piercing (material-color) since runtime validation now becomes an important part of the API. TypeScript does not let us infer these props. My intention with the todo was to fall back to setting string keys if piercing fails to resolve, but this is difficult to use without some kind of visibility like a warning or error for undefined props. Perhaps there's a way we can support snake case props in a way where we keep validation? Consider the following routine:
|
…er error handling
@CodyJasonBennett Thanks for the detailed feedback! I've implemented the 3-step routine as suggested:
|
Thanks for the discussion everyone. It's great when we work together for the best solution. I think having a 3-step routine is good. It should be easy to explain and follow. However, does this solve the issue of a bundler plugin inserting Also, I think we should emit our own error when the traversal fails. This will let us also downgrade it to a warning when we need to. |
The R3F components inside Canvas probably don’t actually render as real DOM elements? If that’s the case, it seems like data-* and aria-* attributes not working isn’t really a problem. |
I wouldn’t have considered it either but this PR was created to address situations where a bundler adds it for testing with dev tools: #3573 I wonder if it still works even if the property is not actually written to the object? |
I use locatorjs in my project, but the goal of this PR isn't to enable locatorjs functionality on Three.js elements. |
Okay thanks for the clarification. Just to be extra clear, none of your use cases require |
@krispya Correct! |
Okay I'll clean this PR up and merge it today unless someone objects. |
@krispya Hello, may I ask when the next release that includes this change will be published? The current version is still from July. |
I now released v9.4.0 which contains this fix. |
Thanks Cody. Sorry folks, I went on a trip and got distracted from this! |
Fixes an issue with unknown props causing errors when applied to Three.js objects.