Skip to content

Commit

Permalink
revert(nodeOps): add check for null props (#829)
Browse files Browse the repository at this point in the history
  • Loading branch information
andretchen0 authored Sep 8, 2024
1 parent bea583f commit 04b001b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/core/nodeOps.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,13 @@ describe('nodeOps', () => {
it('throws an error if tag does not exist in catalogue', () => {
expect(() => { nodeOps.createElement('THIS_TAG_DOES_NOT_EXIST', undefined, undefined, {}) }).toThrow()
})

it('does not throw an error if `props` is `null`', () => {
expect(() => { nodeOps.createElement('TresPerspectiveCamera', undefined, undefined, null) }).not.toThrow()
expect(() => { nodeOps.createElement('TresMesh', undefined, undefined, null) }).not.toThrow()
expect(() => { nodeOps.createElement('TresBoxGeometry', undefined, undefined, null) }).not.toThrow()
expect(() => { nodeOps.createElement('TresMeshNormalMaterial', undefined, undefined, null) }).not.toThrow()
})
})

describe('insert', () => {
Expand Down
4 changes: 3 additions & 1 deletion src/core/nodeOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ const supportedPointerEvents = [
export const nodeOps: (context: TresContext) => RendererOptions<TresObject, TresObject | null> = (context) => {
const scene = context.scene.value

function createElement(tag: string, _isSVG: undefined, _anchor: any, props: Partial<WithMathProps<TresObject>> = {}): TresObject | null {
function createElement(tag: string, _isSVG: undefined, _anchor: any, props: Partial<WithMathProps<TresObject>> | null): TresObject | null {
if (!props) { props = {} }

if (!props.args) {
props.args = []
}
Expand Down

0 comments on commit 04b001b

Please sign in to comment.