fix(RTTR): set initial size for NaN in viewport #3137
Merged
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.
Overview
This PR addresses issue #3133. It includes two main changes:
viewport
andcamera
objects by explicitly creating the size object in theconfigure
function to ensure proper passing of width and height properties.useThree
hook to accurately reflect and validate the size object's structure, using specific dimensions to improve test reliability.These changes ensure that the
configure
function correctly handles size properties, and the updated test verifies this functionality effectively.Process
I began by inspecting the source files for the
fiber
package. I noticed that the configure function (returned by the createRoot function) requires the desired width and height (among other size attributes) to be within asize
object. It does not acceptwidth
andheight
directly.Upon inspecting source files for the
test-renderer
package, I noticed that the structure of the props were being passed to the configure function like so:given that the docs show that the structure of the createOptions prop is
This is not in agreement with the observation that, essentially,
width
andheight
should be part of asize
object.Potential Fixes:
size
object, containing the desiredwidth
andheight
, ALONG withtop
andleft
, as the second parameter of the create function, like so:however, this approach might cause issues with existing tests written with RTTR, which I believe may not be ideal. Moreover, it will require typescript users to explicitly pass
top
andleft
props, astype Size
requirestop
andleft
to be defined.size
object containing the user inputwidth
andheight
attributes, along with other default required attributes, in thecreate
function and also passing any other props that may be added in the future. The code is:with this fix, no changes will be needed in the way the api is used, however the code is slightly complex and redundant. It may serve as a workable fix until the maintainers see fit to release a new version for the api.
This PR is implementing the 2nd fix.
Results
The original issue is resolved. The
NaN
values are gone and theviewport
is calculated as expected. Moreover, theNaN
values incamera
are also resolved. Here is an example result for theviewport
, if thewidth
is set to1280
andheight
is set to800
The test for the
useThree()
hook was also updated to reflect the correct calculation of thesize
object.Feedback and suggestions for improvements are welcome. @CodyJasonBennett, your guidance on enhancing this PR would be greatly appreciated.