Skip to content

Commit

Permalink
fix: a regression related to safe callbacks which could generate a 0 …
Browse files Browse the repository at this point in the history
…width upon certain race conditions
  • Loading branch information
orefalo committed Oct 5, 2024
1 parent 5c9e2d2 commit af34b41
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/lib/Pane.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,24 @@
const carefullClientCallbacks = browser
? carefullCallbackSource(() => clientCallbacks)
: carefullCallbackSource(() => undefined);
// REACTIVE
: undefined;
const reportGivenSizeChangeSafe = (size: number) => {
// This extra check (`size !== sz`) is here and not in the reactive statement, to prevent a trigger on `sz` mutations.
if (size !== sz) {
carefullClientCallbacks('reportGivenSizeChange')(size);
// We put an extra check of `size != sz` here and not in the reactive statement, since we don't want a change
// of `sz` to trigger report.
if (clientCallbacks && size != sz) {
carefullClientCallbacks?.('reportGivenSizeChange')(size);
}
};
// REACTIVE
$: {
if (browser && typeof size === 'number') {
reportGivenSizeChangeSafe(size);
}
}
$: dimension = getDimensionName($isHorizontal);
$: style = `${dimension}: ${sz}%;`;
if (gathering && ssrRegisterPaneSize) {
Expand Down Expand Up @@ -115,10 +114,10 @@
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
class="splitpanes__splitter {isSplitterActive ? 'splitpanes__splitter__active' : ''}"
on:mousedown={carefullClientCallbacks('onSplitterDown')}
on:touchstart={carefullClientCallbacks('onSplitterDown')}
on:click={carefullClientCallbacks('onSplitterClick')}
on:dblclick={carefullClientCallbacks('onSplitterDblClick')} />
on:mousedown={carefullClientCallbacks?.('onSplitterDown')}
on:touchstart={carefullClientCallbacks?.('onSplitterDown')}
on:click={carefullClientCallbacks?.('onSplitterClick')}
on:dblclick={carefullClientCallbacks?.('onSplitterDblClick')} />
{/if}

<!-- Pane -->
Expand All @@ -128,7 +127,7 @@
<div
class={`splitpanes__pane ${clazz || ''}`}
bind:this={element}
on:click={carefullClientCallbacks('onPaneClick')}
on:click={carefullClientCallbacks?.('onPaneClick')}
{style}>
<slot />
</div>
Expand Down

0 comments on commit af34b41

Please sign in to comment.