|
1 | | -import * as THREE from 'three' |
2 | | -import { UseBoundStore } from 'zustand' |
3 | 1 | import Reconciler from 'react-reconciler' |
4 | | -import { unstable_IdlePriority as idlePriority, unstable_scheduleCallback as scheduleCallback } from 'scheduler' |
5 | 2 | import { DefaultEventPriority } from 'react-reconciler/constants' |
| 3 | +import { unstable_IdlePriority as idlePriority, unstable_scheduleCallback as scheduleCallback } from 'scheduler' |
| 4 | +import * as THREE from 'three' |
| 5 | +import { UseBoundStore } from 'zustand' |
| 6 | +import { EventHandlers, removeInteractivity } from './events' |
| 7 | +import { RootState } from './store' |
6 | 8 | import { |
7 | | - is, |
8 | | - prepare, |
9 | | - findInitialRoot, |
10 | | - diffProps, |
11 | 9 | DiffSet, |
12 | 10 | applyProps, |
13 | | - updateInstance, |
14 | | - invalidateInstance, |
15 | 11 | attach, |
16 | 12 | detach, |
| 13 | + diffProps, |
| 14 | + findInitialRoot, |
| 15 | + invalidateInstance, |
| 16 | + is, |
| 17 | + prepare, |
| 18 | + updateInstance, |
17 | 19 | } from './utils' |
18 | | -import { RootState } from './store' |
19 | | -import { EventHandlers, removeInteractivity } from './events' |
20 | 20 |
|
21 | 21 | export type Root = { fiber: Reconciler.FiberRoot; store: UseBoundStore<RootState> } |
22 | 22 |
|
@@ -85,7 +85,19 @@ interface Catalogue { |
85 | 85 | export const catalogue: Catalogue = {} |
86 | 86 | const extend = (objects: object): void => void Object.assign(catalogue, objects) |
87 | 87 |
|
88 | | -function createRenderer<TCanvas>(_roots: Map<TCanvas, Root>, _getEventPriority?: () => any) { |
| 88 | +type OnTextInstanceOption = 'noop' | 'warn' | 'throw' |
| 89 | + |
| 90 | +interface RendererOptions { |
| 91 | + onTextInstance?: OnTextInstanceOption |
| 92 | +} |
| 93 | + |
| 94 | +function createRenderer<TCanvas>( |
| 95 | + _roots: Map<TCanvas, Root>, |
| 96 | + _getEventPriority?: () => any, |
| 97 | + options: RendererOptions = {}, |
| 98 | +) { |
| 99 | + const { onTextInstance = 'warn' } = options |
| 100 | + |
89 | 101 | function createInstance( |
90 | 102 | type: string, |
91 | 103 | { args = [], attach, ...props }: InstanceProps, |
@@ -301,9 +313,20 @@ function createRenderer<TCanvas>(_roots: Map<TCanvas, Root>, _getEventPriority?: |
301 | 313 | }) |
302 | 314 | } |
303 | 315 |
|
304 | | - // Don't handle text instances, warn on undefined behavior |
305 | | - const handleTextInstance = () => |
306 | | - console.warn('Text is not allowed in the R3F tree! This could be stray whitespace or characters.') |
| 316 | + const handleTextInstance = (text: string) => { |
| 317 | + switch (onTextInstance) { |
| 318 | + case 'noop': { |
| 319 | + break |
| 320 | + } |
| 321 | + case 'throw': { |
| 322 | + throw new Error(`Text is not allowed in the R3F tree! This could be stray whitespace or characters: "${text}"`) |
| 323 | + } |
| 324 | + case 'warn': |
| 325 | + default: { |
| 326 | + console.warn(`Text is not allowed in the R3F tree! This could be stray whitespace or characters: "${text}"`) |
| 327 | + } |
| 328 | + } |
| 329 | + } |
307 | 330 |
|
308 | 331 | const reconciler = Reconciler< |
309 | 332 | HostConfig['type'], |
@@ -445,4 +468,4 @@ function createRenderer<TCanvas>(_roots: Map<TCanvas, Root>, _getEventPriority?: |
445 | 468 | return { reconciler, applyProps } |
446 | 469 | } |
447 | 470 |
|
448 | | -export { prepare, createRenderer, extend } |
| 471 | +export { createRenderer, extend, prepare } |
0 commit comments