Skip to content

Commit

Permalink
fix: improve determinism in transition stores
Browse files Browse the repository at this point in the history
  • Loading branch information
divdavem committed Nov 14, 2024
1 parent dd0c588 commit b8f6ee3
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions core/src/services/transitions/baseTransitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ export const createTransition = (config?: PropsConfig<TransitionProps>): Transit
promise: Promise<void>;
},
);
const transitioning$ = computed(() => !!currentTransition$());
const stop = () => {
let context: object | undefined;
currentTransition$.update((currentTransition) => {
Expand Down Expand Up @@ -283,10 +282,7 @@ export const createTransition = (config?: PropsConfig<TransitionProps>): Transit
return currentTransition;
});

const shown$ = computed(() => !transitioning$() && visible$() && elementPresent$());
const hidden$ = computed(() => !transitioning$() && !visible$());
const effectiveAnimation$ = computed(() => (initDone$() ? animated$() : animatedOnInit$()));

const animationFromToggle$ = writable(null as null | boolean);
let previousElement: SSRHTMLElement | null;
let previousVisible = requestedVisible$();
Expand Down Expand Up @@ -355,6 +351,19 @@ export const createTransition = (config?: PropsConfig<TransitionProps>): Transit
}
};

const transitioning$ = computed(() => {
if (elementPresent$()) {
// if the element is present, visibleAction$ can start a transition,
// so it must be updated before currentTransition$ is checked
// so that we don't have an intermediate state
// where transitioning$ is false just before it becomes true
void visibleAction$();
}
return !!currentTransition$();
});
const shown$ = computed(() => !transitioning$() && visible$() && elementPresent$());
const hidden$ = computed(() => !transitioning$() && !visible$());

const directive = mergeDirectives(storeDirective, directiveSubscribe(visibleAction$));

return {
Expand Down

0 comments on commit b8f6ee3

Please sign in to comment.