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

if-with-transition #161

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
21 changes: 16 additions & 5 deletions src/utils/control-flow/if.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ import {
} from '@/utils/shared';
import { opcodeFor } from '@/utils/vm';

export function startViewTransition(callback: () => void | Promise<void>){
if (document.startViewTransition) {
return document.startViewTransition(callback).ready;
} else {
return Promise.resolve().then(callback);
}
}

export class IfCondition {
isDestructorRunning = false;
prevComponent: GenericReturnType | null = null;
Expand Down Expand Up @@ -169,11 +177,14 @@ export class IfCondition {
if (IS_DEV_MODE) {
$DEBUG_REACTIVE_CONTEXTS.pop();
}
renderElement(
this.placeholder.parentNode || this.target,
this.prevComponent,
this.placeholder,
);
startViewTransition(() => {
renderElement(
this.placeholder.parentNode || this.target,
this.prevComponent,
this.placeholder,
);
});

return;
}
async destroy() {
Expand Down
17 changes: 17 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,23 @@ declare global {
const REACTIVE_MODIFIERS: boolean;
const WITH_HELPER_MANAGER: boolean;
const WITH_MODIFIER_MANAGER: boolean;

interface Document {
startViewTransition(
updateCallback: () => Promise<void> | void,
): ViewTransition;
}

interface ViewTransition {
finished: Promise<void>;
ready: Promise<void>;
updateCallbackDone: Promise<void>;
skipTransition(): void;
}

interface CSSStyleDeclaration {
viewTransitionName: string;
}
}

declare module 'glint-environment-gxt/globals' {
Expand Down
Loading