v8.x.x
#2164
Replies: 2 comments
-
i have been using createPortal for portaling Html (react-drei) elements inside existing Mesh elements, after the latters have rendered. I am facing 2 problems and wanted to check if those issues are "normal" or have to do with my specific setup:
am i doing anything wrong ? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi! Thank you so much for the update! |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
title: 'v8 Migration Guide'
description: Changes and new features with v8 and react 18
nav: 13
Work on version 8 has begun 3 Sep 2021 and is perhaps the biggest update to Fiber yet. We've tried our best to keep breaking-changes to a minimum, they mostly affect rarely used api's like
attach
. This release brings a ton of performance related fixes, but also includes some new and ground breaking features.We would like to express our gratitude to the community for their continued support, as well as to all our contributors. 🎉
React Native support
With React 18 and Expo 43, you can now ship threejs goodness across web and native. These apps are not confined to a web-view, they are truly native OpenGLES.
Now expo-gl, which does the hard lifting, has existed for a while, but we've addressed some of the common concerns related to interop and making the three eco system readily work in the native space. For instance, you handle assets the same exact way you'd treat them in a web app.
See installation to get started with managed Expo or bare React Native apps.
This is complete with support for Pressability events and native threejs loaders. See events for a complete list of events.
React Native support was submitted by @Cody_J_Bennett. 🎉
Zustand and suspend-react
Fiber uses zustand to manage state. It's a simple, powerful, and performant state management library for React. And suspend-react to manage async ops and suspense (useLoader for instance). You can use these in your projects as well as they are to get closer interop with Fiber.
New pixel ratio default
The default DPR has changed from
1
to[1, 2]
, which will clamp between 1 and 2, but prefer 2, depending on the screen's native pixel ratio.This was the most common setting in the wild, so it was brought in as a better default.
Color management
Color management is now being handled by Three R139. Therefore we set
THREE.ColorManagement.legacyMode
tofalse
and cede to touch colors and textures since everything will now be converted from sRGB to linear space by Three itself.While you can of course use Fiber with any Three version you like we recommend updating to R139.
Check out https://threejs.org/docs/index.html#manual/en/introduction/Color-management for information.
Automatic concurrency
Concurrency is now part of React 18, which automatically switches between blocking (default) and concurrent (async).
React 18 introduces the
startTransition
anduseTransition
APIs to defer and schedule expensive operations and state updates. Use these to de-prioritize expensive operations.Examples
Please be careful, this is an extreme stress test. It creates so much load that without React the browser will freeze or crash.
Conditional rendering with frameloop
frameloop
can now be toggled to render conditionally. This is useful to toggle on user interaction or while in frame.Another usecase would be using intersection observers to stop the canvas when it's out of view.
Expanded gl prop
The
gl
prop can now accept both constructor args and renderer properties like thecamera
prop.It can also accept a synchronous callback to manually create a renderer. This allows you to use any custom renderer you want.
Improved WebXR handling
Automatic WebXR switching
The
vr
prop was removed in favor of automatic WebXR switching. Whenever a session is requested, XR features are enabled, and the renderer will render at the native refresh rate. The inverse is true when exiting a session.Extended useFrame
In addition to the automatic rendering, useFrame will expose the current
XRFrame
obtained via XRSession#requestAnimationFrame.This removes the need for custom rendering loops when using WebXR pose data and abstractions like
useXRFrame
of @react-three/xr.Manual camera manipulation
By default Fiber is responsive and will set up cameras properly on resize (aspect ratio etc).
Cameras can be controlled manually by setting
manual
to true incamera
. This will opt out of projection matrix recalculation when the drawing area resizes.This is also supported by all cameras that you create, be it a THREE.PerspectiveCamera or drei/cameras, put
manual
on it and Fiber will not touch it.Unified attach API
Previously, attach had multiple signatures:
attach="name"
attachObject={["name", "attribute"]}
attachArray="name"
attachFns={["add", "remove"]}
attachFns={[(self, parent) => parent.add(self), (self, parent) => parent.remove(self)]}
This is now a single, unified signature with support for piercing and named attach functions or custom handlers.
Real-world use-cases:
Attaching to nested objects:
Arrays must be explcit now:
Spread Canvas props
The
<Canvas />
can now accept non-render props to spread as native props: styles, classes, events, a11y, ...New createRoot API
render
is depreciated in v8 for the newcreateRoot
signature.Here is a typical setup:
Examples
This is a custom-renderer example using the createRoot api:
Tree-shaking via extend
The underlying reconciler no longer pulls in the THREE namespace automatically.
This enables a granular catalogue and tree-shaking via the
extend
API:There's an official babel plugin which will do this for you automatically:
No changes are necessary for
@react-three/test-renderer
as THREE is extended automatically.createPortal creates a state enclave
createPortal
allows you to write a declarative JSX scene into a pre-existing, foreign object. This has been very useful for portals, heads-up displays, view-cubes, view splitting, etc.But these things were very limited and lacked event support as well as support for eco-system packages (for instance putting OrbitControls into a split view).
With this release
createPortal
creates a virtual state-model in which everything keeps functioning. Events work, you can use any 3rd party eco-system control and throw it in there.The event layering part of this was submitted by @theatre_js and @AndrewPrifer 🎉.
The event system in particular can now be layered, so that you can have portals inside portals with event priority. You can also inject objects into RootState right away, these will become the defaults inside the portalled state world and anything using
useThree
inside will receive these objects.Here is an example of a layered portal:
createPortal
can still be considered low-level and the exact API forcompute
is still experimental at this point. Expect ready-made components for portals, hud's and view-splitting to come to drei soon.Examples
RTTR Regex Matchers
test-renderer's
findByProps
andfindAllByProps
now accept RegExp matchers to search for variable or computed properties.React-three-test-renderer was submitted by @josh_ellis 🎉.
Deprecated
This discussion was created from the release v8.x.x.
Beta Was this translation helpful? Give feedback.
All reactions