Skip to content
This repository was archived by the owner on Sep 30, 2024. It is now read-only.

Commit 8b5eec2

Browse files
authored
fix(svelte): Data/code preloading doesn't work when using panels (#63339)
Fixes srch-507 The panels code prevents event propagation of mouse move events, which in turn seems to prevent SvelteKit from its own preloading logic. Looking at the event handlers it seems they are global only (per document), so I don't think that stopping the propagation is necessary for the panel itself to work. However, I think it makes sense to stop any of default event behavior when the mouse is currently pressed, since that means the user is currently dragging a resize handler. Would love to get @vovakulikov's confirmation that my understanding is correct. ## Test plan Manual testing. Changing the size of a panel (e.g. repo page) seems to work as expected. Hovering over a file tree entry preloads data and code now, as visible in the network tab.
1 parent 29e07b7 commit 8b5eec2

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

client/web-sveltekit/src/lib/wildcard/resizable-panel/PanelResizeHandleRegistry.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ export class PanelResizeHandleRegistry {
8383
const { body } = ownerDocument
8484

8585
body.removeEventListener('contextmenu', PanelResizeHandleRegistry.handlePointerUp)
86-
body.removeEventListener('mousedown', PanelResizeHandleRegistry.handlePointerDown)
86+
body.removeEventListener('mousedown', PanelResizeHandleRegistry.handlePointerDown, { capture: true })
8787
body.removeEventListener('mouseleave', PanelResizeHandleRegistry.handlePointerMove)
8888
body.removeEventListener('mousemove', PanelResizeHandleRegistry.handlePointerMove)
8989
body.removeEventListener('touchmove', PanelResizeHandleRegistry.handlePointerMove)
90-
body.removeEventListener('touchstart', PanelResizeHandleRegistry.handlePointerDown)
90+
body.removeEventListener('touchstart', PanelResizeHandleRegistry.handlePointerDown, { capture: true })
9191
})
9292

9393
window.removeEventListener('mouseup', PanelResizeHandleRegistry.handlePointerUp)
@@ -119,12 +119,18 @@ export class PanelResizeHandleRegistry {
119119
const { body } = ownerDocument
120120

121121
if (count > 0) {
122-
body.addEventListener('mousedown', PanelResizeHandleRegistry.handlePointerDown)
122+
// Capturing to prevent any other listeners from being triggered when the user really wants
123+
// to resize a panel
124+
body.addEventListener('mousedown', PanelResizeHandleRegistry.handlePointerDown, {
125+
capture: true,
126+
})
123127
body.addEventListener('mousemove', PanelResizeHandleRegistry.handlePointerMove)
124128
body.addEventListener('touchmove', PanelResizeHandleRegistry.handlePointerMove, {
125129
passive: false,
126130
})
127-
body.addEventListener('touchstart', PanelResizeHandleRegistry.handlePointerDown)
131+
body.addEventListener('touchstart', PanelResizeHandleRegistry.handlePointerDown, {
132+
capture: true,
133+
})
128134
}
129135
})
130136
}
@@ -169,16 +175,18 @@ export class PanelResizeHandleRegistry {
169175
static handlePointerMove(event: ResizeEvent) {
170176
const { x, y } = getResizeEventCoordinates(event)
171177

172-
event.preventDefault()
173-
event.stopImmediatePropagation()
174-
175178
if (!PanelResizeHandleRegistry.isPointerDown) {
176179
const { target } = event
177180

178181
// Recalculate intersecting handles whenever the pointer moves, except if it has already been pressed
179182
// at that point, the handles may not move with the pointer (depending on constraints)
180183
// but the same set of active handles should be locked until the pointer is released
181184
PanelResizeHandleRegistry.recalculateIntersectingHandles({ target, x, y })
185+
} else {
186+
// These are required to prevent default browser behavior when dragging started not precisely on the handle
187+
// For example when starting to drag the history panel up, the file content would be selected without these
188+
event.preventDefault()
189+
event.stopImmediatePropagation()
182190
}
183191

184192
PanelResizeHandleRegistry.updateResizeHandlerStates('move', event)

0 commit comments

Comments
 (0)