Skip to content

perf(Select): fix update loop - #237

Closed
donalffons wants to merge 3 commits into
pmndrs:masterfrom
donalffons:master
Closed

perf(Select): fix update loop#237
donalffons wants to merge 3 commits into
pmndrs:masterfrom
donalffons:master

Conversation

@donalffons

Copy link
Copy Markdown

See #236 for additional details

Would be great to hear your feedback on this. This code

constchanged=(current.length!==api.selected.length) ? true : !current.every(o=>api.selected.includes(o))

is only correct if there are no duplicates in any of the two arrays (otherwise, they would have to be de-duped first) - but I believe that is the case here.

@donalffons

Copy link
Copy Markdown
Author

Hmm after testing this further, I realized that this doesn't work in the case of

<Canvas><Selection><Selectenabled><Boxname="box"/></Select><Selectenabled={false}></Select></Selection></Canvas>

I will look into this some more...

@donalffons

Copy link
Copy Markdown
Author

I've played with this a bit more and I believe this fix is now working as intended.

@drcmda

Copy link
Copy Markdown
Member

is it ready to go in? did you notice any adverse effects on older boxes?

@CodyJasonBennettCodyJasonBennett changed the title Fix update loop caused by Selectperf(Select): fix update loopAug 23, 2023
Comment threadsrc/Selection.tsx
Comment on lines -25 to +33
if (api && enabled) {
let changed = false
const current: THREE.Object3D<THREE.Event>[] = []
group.current.traverse((o) => {
o.type === 'Mesh' && current.push(o)
if (api.selected.indexOf(o) === -1) changed = true
})
if (changed) {
api.select((state) => [...state, ...current])
return () => {
api.select((state) => state.filter((selected) => !current.includes(selected)))
}
}
if (!api) return
const current: THREE.Object3D<THREE.Event>[] = []
group.current.traverse((o) => {
if (o.type === 'Mesh') current.push(o)
})
if (enabled && current.some(o => !api.selected.includes(o))) {
api.select(state => [...state, ...current])
} else if (!enabled && current.some(o => api.selected.includes(o))) {
api.select(state => state.filter(o => !current.includes(o)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove the cleanup handler? I'm not sure I understand when L33 is supposed to happen in the case of a Select unmounting with any number of siblings rather than parents who rerender when children change (e.g. <Selection> <Select /> <Select /> </Selection>).

@kvvasuu

kvvasuu commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

Superseded by #359 - closing.

@kvvasuukvvasuu closed this Aug 2, 2026
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

@donalffons@drcmda@kvvasuu@CodyJasonBennett