Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: improve determinism in transition stores #804

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading