
Security News
The Hidden Blast Radius of the Axios Compromise
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.
@react-three/offscreen
Advanced tools
npm install three @react-three/fiber @react-three/offscreen
This is an experimental package that allows you to render your react-three-fiber scene with an offscreen canvas in a web worker. This is mostly useful for self-contained webgl apps, and un-blocking the main thread.
The package will forward DOM events to the worker so you can expect mostly everything to run fine. It will even shim a basic document/window interface so that camera controls and various threejs classes that must interact with the DOM have something to work with.
For better interop all non-passive events (click, contextmenu, dlbclick) will preventDefault, pointerdown will capture, pointerup will release capture.
Instead of importing <Canvas> from @react-three/fiber you can import it from @react-three/offscreen and pass a worker prop. The fallback prop is optional, your scene will be rendered on the main thread, in a regular canvas, where OffscreenCanvas is not supported (Safari).
It takes all other props that <Canvas> takes (dpr, shadows, etc), you can use it as a drop-in replacement.
// App.jsx (main thread)
import { lazy } from 'react'
import { Canvas } from '@react-three/offscreen'
// This is the fallback component that will be rendered on the main thread
// This will happen on systems where OffscreenCanvas is not supported
const Scene = lazy(() => import('./Scene'))
// This is the worker thread that will render the scene
const worker = new Worker(new URL('./worker.jsx', import.meta.url), { type: 'module' })
export default function App() {
return (
<Canvas
worker={worker} fallback={<Scene />}
shadows camera={{ position: [0, 5, 10], fov: 25 }} />
)
}
Your worker thread will be responsible for rendering the scene. The render function takes a single argument, a ReactNode. React-three-fiber and its React-root/reconciler will run in that worker, rendering your contents.
// worker.jsx (worker thread)
import { render } from '@react-three/offscreen'
render(<Scene />)
Your app or scene should be self contained, meaning it shouldn't interact with the DOM. This is because offscreen canvas + webgl is still not supported in Safari. If you must communicate with the DOM, you can use the web broadcast API.
In your worker app you can use most of what is available in the eco system, drei, physics, postpro etc. You can also use assets (gltf, textures, ...). Even controls will work. You will run into problems for everything that requires a DOM to be present (drei/Html/View/...).
// Scene.jsx (a self contained webgl app)
export default function App() {
return (
<mesh>
<boxGeometry />
</mesh>
)
}
Just make sure to disable SSR for the canvas component because Worker only exists in the DOM:
// src/app/page.jsx
import dynamic from 'next/dynamic'
const App = dynamic(() => import('@/components/App'), { ssr: false })
Vites @vitejs/plugin-react tries to inject styles into document and assumes the presence of window, neither exist in a worker. As such you can consider the official React plugin faulty, it won't run React in a web worker. The workaround:
export default defineConfig({
plugins: [react({ fastRefresh: false })],
worker: { plugins: [react()] },
})
FAQs
Worker offscreen canvas for react three fiber
The npm package @react-three/offscreen receives a total of 2,208 weekly downloads. As such, @react-three/offscreen popularity was classified as popular.
We found that @react-three/offscreen demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 21 open source maintainers collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
The Axios compromise shows how time-dependent dependency resolution makes exposure harder to detect and contain.

Research
A supply chain attack on Axios introduced a malicious dependency, plain-crypto-js@4.2.1, published minutes earlier and absent from the project’s GitHub releases.

Research
Malicious versions of the Telnyx Python SDK on PyPI delivered credential-stealing malware via a multi-stage supply chain attack.