๋ฒ๊ทธ ์ค๋ช
react-dnd๊ฐ ๊ตฌ์ฑ ์์๋ฅผ ๋ง์ดํธ ํด์ ํ๋๋ก ํ๋ ์์ง ํจ์๋ฅผ ํธ์ถํ ๋ค์ ๋ง์ดํธ ํด์ ๋ ๊ตฌ์ฑ ์์์ ๋ํด ๋ ๋ค๋ฅธ collect() ํธ์ถ์ ์ํํ์ฌ "์ฌ๋ฐ๋ฅธ targetId๋ฅผ ์ฐพ์ ์ ์์" ์ค๋ฅ๊ฐ ๋ฐ์ํ ์ ์์ต๋๋ค.
๋ฐฑ์๋ ๋๋๊ทธ ์ค ๋๋กญ ์ด๋ฒคํธ์ dispatch()์ ๋ํ Redux๋ ์ฒ์์ ๊ตฌ๋ ์ด๋ฒคํธ์ ๋ํ ๋ชจ๋ ์์ ๊ธฐ์ ๋ณต์ฌ๋ณธ์ ๋ง๋ค๊ณ ๊ตฌ๋ ์์๊ฒ ์๋ฆฌ๋ ๋์ ๊ตฌ๋ ์ทจ์๋ redux ๊ตฌ๋ ์ ๊ด๊ณ์์ด ํญ์ ํธ์ถํฉ๋๋ค(https://stackoverflow.com/questions ์ฐธ์กฐ). /43356080/redux-unsubscribe-within-componentwillunmount-still-calls-subscribe-callback). ์ฆ, 'EndDrag' html5 ๋๋๊ทธ ์ด๋ฒคํธ์ ๊ฐ์ ๊ฒ์ด react-dnd/src/decorateHandler.tsx:handleChange()์ handleChange()์์ ์๋ฆผ์ ํธ๋ฆฌ๊ฑฐํ๊ณ ์ฒซ ๋ฒ์งธ collect() ํธ์ถ๋ก ๊ตฌ์ฑ ์์์ ๋ง์ดํธ ํด์ ๊ฐ ๋ฐ์ํ๋ฉด ๋ง์ดํธ ํด์ ๋ ํ์ ๊ตฌ์ฑ ์์๋ ๋์ผํ ์ด๋ฒคํธ์ ํ์ ์๋ฆผ์์ ํด๋น collect() ํธ์ถ์ด ํธ๋ฆฌ๊ฑฐ๋ ์ ์์ต๋๋ค.
๋ฐ๋ผ์ ๊ตฌ์ฑ ์์๊ฐ ์ ํจํ ๋์ ID์ ๋ ์ง์คํธ๋ฆฌ์์ ์ ํจํ๊ฒ ์ ๊ฑฐ๋์์ง๋ง ์๋ฆผ์ด ๋ง์ดํธ ํด์ ๋ ๊ตฌ์ฑ ์์๋ฅผ ํธ์ถํ๊ธฐ ๋๋ฌธ์ ๋ถ๋ณ '์ ํจํ ๋์์ ์ฐพ์ ๊ฒ์ผ๋ก ์์๋จ'์ด ํธ๋ฆฌ๊ฑฐ๋ฉ๋๋ค.
react-dnd๋ฅผ ์ฌ์ฉํ๋ react-sortable-tree๋ฅผ ๋ด ์ฑ์ ํตํฉํ๋ ค๊ณ ์๋ํ๋ ๋์ ์ด ๋ฌธ์ ๋ฅผ ๋ฐ๊ฒฌํ์ต๋๋ค. https://github.com/frontend-collective/react-sortable-tree/issues/490์์ ๋ฌธ์ ์ ์์ ์ฌํ ๊ฐ๋ฅํ ํ ์คํธ ์ฌ๋ก๋ฅผ ๋ณผ ์ ์์ต๋๋ค. dragTarget ์ธ๋ถ์์ dragSource๋ฅผ ํด์ ํ์ฌ ์ทจ์๋๋ ๋๋๊ทธ ์ค ๋๋กญ์ ๋งค๋ฒ ์ด ๋ฌธ์ ๋ฅผ ์ฌํํฉ๋๋ค.
ํฌ์ฐฉ๋์ง ์์ ์ค๋ฅ ๋ฐ ์คํ ์ถ์ ์ด ์๋์ ๋ถ์ฌ๋ฃ์ด์ง๋๋ค. ์คํ ์ถ์ ์ ์ฐ๊ฒฐ ํจ์๊ฐ ๋ง์ดํธ ํด์ ๋ ๊ตฌ์ฑ ์์์์ ์คํจํ๋ monitor.canDrop()์ ํธ์ถํ๊ณ ์์์ ๋ณด์ฌ์ค๋๋ค.
browser.js:38 ์กํ์ง ์์ ๋ถ๋ณ ์๋ฐ: ์ ํจํ ๋์์ ์ฐพ์ ๊ฒ์ผ๋ก ์์๋ฉ๋๋ค.๋ถ๋ณ์์ (https://xzoq6xprlz.codesandbox.io/node_modules/invariant/browser.js:38:15)DragDropMonitorImpl.canDropOnTarget์์ (https://xzoq6xprlz.codesandbox.io/node_modules/dnd-core/lib/cjs/DragDropMonitorImpl.js:67:9)
DropTargetMonitorImpl.canDrop์์ (https://xzoq6xprlz.codesandbox.io/node_modules/react-dnd/lib/cjs/DropTargetMonitorImpl.js:24:41)
nodeDropTargetPropInjection์์ (https://xzoq6xprlz.codesandbox.io/node_modules/react-sortable-tree/dist/index.cjs.js:2367:28)
DragDropContainer.getCurrentState์์ (https://xzoq6xprlz.codesandbox.io/node_modules/react-dnd/lib/cjs/decorateHandler.js:116:29)
DragDropContainer._this.handleChange์์ (https://xzoq6xprlz.codesandbox.io/node_modules/react-dnd/lib/cjs/decorateHandler.js:45:39)
ํธ๋ค ๋ณ๊ฒฝ ์(https://xzoq6xprlz.codesandbox.io/node_modules/dnd-core/lib/cjs/DragDropMonitorImpl.js:27:21)
ํ๊ฒฌ ์ (https://xzoq6xprlz.codesandbox.io/node_modules/redux/lib/redux.js:220:7)
Object.eval์์ [endDrag๋ก] (https://xzoq6xprlz.codesandbox.io/node_modules/dnd-core/lib/cjs/DragDropManagerImpl.js:67:21)
HTML5Backend.handleTopDragEndCapture์์ (https://xzoq6xprlz.codesandbox.io/node_modules/react-dnd-html5-backend/lib/cjs/HTML5Backend.js:145:31)
``
๋ง์ดํธ ํด์ ๋ ๊ตฌ์ฑ ์์๋ฅผ ํธ์ถํ๋ ๊ฒ์ ์๋ง๋ ์ฌ๋ฐ๋ฅธ ๋์์ด ์๋ ์ ์์ผ๋ฏ๋ก, decorHandler๊ฐ ์ด๋ฏธ ๊ตฌ๋ ์ทจ์๋ ๊ฒฝ์ฐ ์๋ฆผ์ ์ญ์ ํ๋ if ๋ฌธ์ react-dnd/src/decorateHandler.tsx:handleChange์ ์ถ๊ฐํ์ต๋๋ค. diff ์ฒจ๋ถ.
diff --git a/packages/react-dnd/src/decorateHandler.tsx b/packages/react-dnd/src/decorateHandler.tsx
index 85385ec..bcd149e 100644
--- a/packages/react-dnd/src/decorateHandler.tsx
+++ b/packages/react-dnd/src/decorateHandler.tsx
@@ -159,6 +159,15 @@ export default function decorateHandler<Props, CollectedProps, ItemIdType>({
}
public handleChange = () => {
+ if (this.disposable.isDisposed) {
+ console.log("in handleChange")
+ //because redux takes a snapshot of all subscribers to
+ //events when it starts dispatch, it is still possible to call into this even after
+ //the subscription has been unsubscribed
+ //to prevent against calling into unmounted objects, return immediately
+
+ return
+ }
const nextState = this.getCurrentState()
if (!shallowEqual(nextState, this.state)) {
this.setState(nextState)
์ด ๋ฌธ์ ๋ ์ต๊ทผ ํ๋์ด ์์๊ธฐ ๋๋ฌธ์ ์๋์ผ๋ก ์ค๋๋ ๊ฒ์ผ๋ก ํ์๋์์ต๋๋ค. ๋ ์ด์ ํ๋์ด ์์ผ๋ฉด ํ์๋ฉ๋๋ค. ๊ทํ์ ๊ธฐ์ฌ์ ๊ฐ์ฌ๋๋ฆฝ๋๋ค.
@mx2323 ์ด๊ฑฐ ๋ฐ๋ฆฐ๊ฑด๊ฐ์? ๊ทธ๊ฒ์ด react-sortable-tree ์๋๋ผ๋ ์ฌ์ ํ ์ต์ react-dnd ์ ๋ฐ์ดํธ๊ฐ ํ์ํ์ง๋ง ๊ธฐ๋ค๋ฆฌ๋ ์ค์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค.
๋๋ ๊ทธ๊ฒ์ ๋ฐ๊ณ ๋๋ด์ง ์์๋ค.
๊ฐ์ฅ ์ ์ฉํ ๋๊ธ
@mx2323 ์ด๊ฑฐ ๋ฐ๋ฆฐ๊ฑด๊ฐ์? ๊ทธ๊ฒ์ด react-sortable-tree ์๋๋ผ๋ ์ฌ์ ํ ์ต์ react-dnd ์ ๋ฐ์ดํธ๊ฐ ํ์ํ์ง๋ง ๊ธฐ๋ค๋ฆฌ๋ ์ค์ด๋ผ๊ณ ์๊ฐํฉ๋๋ค.