Skip to content

Commit cc722cd

Browse files
authored
fix: resolve Solid 2.x context auto-disposal, XR timing, and signal dev-mode warnings
2 parents 5f8d8a1 + c8bc011 commit cc722cd

30 files changed

Lines changed: 2357 additions & 456 deletions

.github/workflows/pkg-pr-new.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,4 @@ jobs:
3636
run: pnpm build
3737

3838
- name: Publish preview
39-
run: pnpx pkg-pr-new publish --compact
39+
run: pnpx pkg-pr-new publish --compact --template ./demo

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
dist
33
types
44
node_modules
5+
demo/node_modules
56
packed/

README.md

Lines changed: 45 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
3. [Components](#components)
2121
- [Canvas](#canvas)
2222
- [T](#t)
23+
- [createEntity](#createentity)
2324
- [Entity](#entity)
2425
- [Portal](#portal)
2526
- [Resource](#resource)
@@ -100,11 +101,11 @@ The `Canvas` component initializes the `three.js` rendering context and acts as
100101

101102
**Props:**
102103

103-
- **defaultCamera**: Configures the camera used in the scene. Can be partial props for a camera or an existing Camera instance.
104+
- **camera**: Configures the camera used in the scene. Can be partial props for a camera or an existing Camera instance.
104105
- **fallback**: Element to render while the main content is loading asynchronously.
105106
- **gl**: Defines options for the WebGLRenderer, a function returning a customized renderer, or an existing renderer instance.
106107
- **scene**: Provides custom settings for the Scene instance or an existing Scene.
107-
- **defaultRaycaster**: Configures the Raycaster for mouse and pointer events.
108+
- **raycaster**: Configures the Raycaster for mouse and pointer events.
108109
- **shadows**: Enables and configures shadows in the scene with various shadow mapping techniques.
109110
- **orthographic**: Toggles between Orthographic and Perspective camera for the default camera.
110111
- **linear**: Toggles linear interpolation for texture filtering.
@@ -122,11 +123,11 @@ The `Canvas` component initializes the `three.js` rendering context and acts as
122123

123124
```tsx
124125
interface CanvasProps {
125-
defaultCamera?: Partial<PerspectiveCamera | OrthographicCamera> | Camera
126+
camera?: Partial<PerspectiveCamera | OrthographicCamera> | Camera
126127
fallback?: JSX.Element
127128
gl?: Partial<WebGLRenderer> | ((canvas: HTMLCanvasElement) => WebGLRenderer) | WebGLRenderer
128129
scene?: Partial<Scene> | Scene
129-
defaultRaycaster?: Partial<Raycaster> | Raycaster
130+
raycaster?: Partial<Raycaster> | Raycaster
130131
shadows?: boolean | "basic" | "percentage" | "soft" | "variance" | WebGLRenderer["shadowMap"]
131132
orthographic?: boolean
132133
linear?: boolean
@@ -312,6 +313,22 @@ const T = createT({ Mesh, BoxGeometry, MeshBasicMaterial })
312313
- **In Libraries**: create multiple `T` to allow for treeshaking or use [`<Entity/>`](#entity) instead
313314
- **Multiple Ts**: Create multiple T instances for lazy loading different parts of three.js
314315
316+
#### createEntity
317+
318+
`createT` is built on top of `createEntity`, which creates a single typed component from one Three.js constructor. Use it directly when you need a one-off component without building a full namespace:
319+
320+
```tsx
321+
import { createEntity } from "solid-three"
322+
import { Mesh } from "three"
323+
324+
const MeshComponent = createEntity(Mesh)
325+
326+
// Equivalent to <T.Mesh /> but without the full namespace
327+
<MeshComponent position={[0, 1, 0]}>
328+
...
329+
</MeshComponent>
330+
```
331+
315332
### Portal
316333
317334
The `Portal` component allows you to place children outside the regular scene graph while maintaining reactive updates. This is useful for rendering objects into different scenes or bypassing the normal parent-child relationships.
@@ -390,7 +407,24 @@ Wrapper-component around ['useLoader'](#useloader).
390407
391408
### useThree
392409
393-
Provides access to the `three.js` context, including the renderer, scene, camera, and more. This hook can be used with or without a selector function for optimized access to specific properties.
410+
Provides access to the `three.js` context, including the renderer, scene, camera, and more.
411+
412+
**Signatures:**
413+
414+
```tsx
415+
// Returns the full context object directly
416+
useThree(): Context
417+
418+
// Returns a reactive accessor for a derived value
419+
useThree<T>(callback: (value: Context) => T): Accessor<T>
420+
```
421+
422+
Use the selector form to derive a specific value reactively:
423+
424+
```tsx
425+
const camera = useThree(ctx => ctx.camera)
426+
// camera() is an Accessor<Camera>
427+
```
394428
395429
**Returns:**
396430
@@ -413,7 +447,7 @@ Provides access to the `three.js` context, including the renderer, scene, camera
413447
`solid-three` implements a stack-based system for managing its current camera and raycaster:
414448
415449
- **Stack-based Management**: Both cameras and raycasters are managed as stacks internally
416-
- **Default at Tail**: The `defaultCamera` and `defaultRaycaster` from Canvas props form the tail of their respective stacks
450+
- **Default at Tail**: The `camera` and `raycaster` from Canvas props form the tail of their respective stacks
417451
- **Current Active Camera at Head**: The camera/raycaster at the top of the stack is the currently active camera/raycaster
418452
- **Push To The Stack To Become Active**: By calling `setCamera(camera)` and `setRaycaster(raycaster)`, the camera/raycaster is pushed to the stack. This causes it to become the currently active camera/raycaster
419453
- **Pop From The Stack To Deactivate**: `setCamera(camera)` and `setRaycaster(raycaster)` return a cleanup-function to pop the camera/raycaster from the stack. If the camera/raycaster was on top of the stack, the previous camera/raycaster in the stack becomes active again
@@ -485,7 +519,7 @@ useFrame(
485519
priority?: number
486520
stage?: "before" | "after"
487521
}
488-
)
522+
): () => void
489523
```
490524
491525
</details>
@@ -745,7 +779,7 @@ const App = () => {
745779
const raycaster = new CursorRaycaster()
746780

747781
// CursorRaycaster is used by default, but you can explicitly set it:
748-
return <Canvas defaultRaycaster={raycaster}>{/* Your scene */}</Canvas>
782+
return <Canvas raycaster={raycaster}>{/* Your scene */}</Canvas>
749783
}
750784
```
751785
@@ -760,7 +794,7 @@ import { CenterRaycaster } from "solid-three"
760794
const App = () => {
761795
const raycaster = new CenterRaycaster()
762796

763-
return <Canvas defaultRaycaster={raycaster}>>{/* Your scene */}</Canvas>
797+
return <Canvas raycaster={raycaster}>>{/* Your scene */}</Canvas>
764798
}
765799
```
766800
@@ -796,7 +830,7 @@ class CustomRaycaster extends Raycaster implements EventRaycaster {
796830
const App = () => {
797831
const raycaster = new CustomRaycaster()
798832

799-
return <Canvas defaultRaycaster={raycaster}>{/* Your scene */}</Canvas>
833+
return <Canvas raycaster={raycaster}>{/* Your scene */}</Canvas>
800834
}
801835
```
802836
@@ -1118,7 +1152,7 @@ const TreePropagation = () => {
11181152
```tsx
11191153
const RayPropagation = () => {
11201154
return (
1121-
<Canvas defaultCamera={{ position: [0, 0, 5] }}>
1155+
<Canvas camera={{ position: [0, 0, 5] }}>
11221156
<T.Mesh
11231157
name="front mesh"
11241158
position={[0, 0, 2]}

demo/.stackblitzrc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"installCommand": "pnpm install",
3+
"startCommand": "pnpm run dev"
4+
}

demo/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
</head>
1313
<body>
1414
<div id="root"></div>
15-
<script src="./main.tsx" type="module"></script>
15+
<script src="./src/main.tsx" type="module"></script>
1616
</body>
1717
</html>

0 commit comments

Comments
 (0)