Skip to content

Commit

Permalink
Fix issue where drag preview wasn't reconnecting in reconnect flow (#…
Browse files Browse the repository at this point in the history
…3353)

* Fix issue where drag preview wasn't reconnecting in `reconnect` flow

* fix: linting issues

* chore: cut semver

* fix: add default argument to reconnectDragPreview

Co-authored-by: Chris Trevino <chtrevin@microsoft.com>
  • Loading branch information
kauffecup and darthtrevino committed Feb 3, 2022
1 parent e8b3579 commit eb91e0e
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
7 changes: 7 additions & 0 deletions .yarn/versions/f6cebe98.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
releases:
react-dnd: patch
react-dnd-test-utils: patch

declined:
- react-dnd-documentation
- react-dnd-examples
1 change: 0 additions & 1 deletion packages/react-dnd/src/hooks/__tests__/useDrag.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useDrag } from '../useDrag'
import { DndProvider } from '../../core'
import { TestBackend } from 'react-dnd-test-backend'
import { render, cleanup } from '@testing-library/react'
import { nextTick } from 'process'

describe('The useDrag hook', () => {
afterEach(cleanup)
Expand Down
14 changes: 8 additions & 6 deletions packages/react-dnd/src/internals/SourceConnector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ export class SourceConnector implements Connector {
}

public reconnect(): void {
this.reconnectDragSource()
this.reconnectDragPreview()
const didChange = this.reconnectDragSource()
this.reconnectDragPreview(didChange)
}

private reconnectDragSource() {
private reconnectDragSource(): boolean {
const dragSource = this.dragSource
// if nothing has changed then don't resubscribe
const didChange =
Expand All @@ -110,11 +110,11 @@ export class SourceConnector implements Connector {
}

if (!this.handlerId) {
return
return didChange
}
if (!dragSource) {
this.lastConnectedDragSource = dragSource
return
return didChange
}

if (didChange) {
Expand All @@ -127,12 +127,14 @@ export class SourceConnector implements Connector {
this.dragSourceOptions,
)
}
return didChange
}

private reconnectDragPreview() {
private reconnectDragPreview(forceDidChange = false): void {
const dragPreview = this.dragPreview
// if nothing has changed then don't resubscribe
const didChange =
forceDidChange ||
this.didHandlerIdChange() ||
this.didConnectedDragPreviewChange() ||
this.didDragPreviewOptionsChange()
Expand Down
2 changes: 1 addition & 1 deletion packages/test-utils/src/testingLibraryEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export async function fireDrag(source: Element) {
})
}

export async function fireReleaseDrag(source: Element) {
export async function fireReleaseDrag() {
await act(async () => {
fireEvent.drop(window)
await tick()
Expand Down

0 comments on commit eb91e0e

Please sign in to comment.