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

framer-motion exit animation 관련 #1

Open
sdh20282 opened this issue Jul 11, 2024 · 3 comments
Open

framer-motion exit animation 관련 #1

sdh20282 opened this issue Jul 11, 2024 · 3 comments

Comments

@sdh20282
Copy link
Owner

sdh20282 commented Jul 11, 2024

  • AnimatePresense exit animation이 app router에서 정상 동작하지 않음
  • page router에서는 정상 동작하는 것 확인
@sdh20282 sdh20282 changed the title framer-motion exit animation error framer-motion exit animation 관련 Jul 11, 2024
@sdh20282
Copy link
Owner Author

sdh20282 commented Jul 14, 2024

export function FrozenRouter(props: { children: React.ReactNode }) {
  const context = useContext(LayoutRouterContext ?? {});
  const frozen = useRef(context).current;

  return (
    <LayoutRouterContext.Provider value={frozen}>
      {props.children}
    </LayoutRouterContext.Provider>
  );
}
  • FrozenRouter를 통해 router가 component를 변경하는 것을 지연
  • 종종 component가 로딩되지 않는 문제 발생

@sdh20282
Copy link
Owner Author

sdh20282 commented Jul 14, 2024

export function FrozenRouter(props: { children: React.ReactNode }) {
  const context = useContext(LayoutRouterContext);
  const prevContext = usePreviousValue(context) || null;
 
  const segment = useSelectedLayoutSegment();
  const prevSegment = usePreviousValue(segment);
 
  const changed = segment !== prevSegment && segment !== undefined && prevSegment !== undefined;
 
  return (
    <LayoutRouterContext.Provider value={changed ? prevContext : context}>
      {props.children}
    </LayoutRouterContext.Provider>
  );
}
  • 기존 코드에서 위의 코드로 FrozenRouter 변경, 내부 컨텐츠가 로딩되지 않는 문제는 수정되었으나 컨텐츠가 빨리 로딩되는 현상 발생, 현재 수정 중
  • 차선책으로 Link를 커스텀하여 사용하는 방법도 검토해보았으나, 뒤로가기와 같이 Link를 통하지 않고 router를 변경하는 경우에는 동작하지 않아서 적용하지 않음

@sdh20282
Copy link
Owner Author

현재 page router로 변경 완료, 자잘한 부분 수정 중

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant