Skip to content

preact/compat: requestAnimationFrame works not the same way as in React 19 #4826

@krutoo

Description

@krutoo
  • Check if updating to the latest Preact version resolves the issue

Describe the bug
Apparently rendering works differently in react and preact in relation to requestAnimationFrame

In Firefox requestAnimationFrame with useLayoutEffect works not the same way as in React 19

Here is a demo of problem:
https://github.com/user-attachments/assets/9a86e4f2-8e7a-441a-b75b-65837397cb74

There is no same problem with React 18/19

To Reproduce

Here is an example repo with simple modal component with implemented open/close transitions:
https://github.com/krutoo/typescript-react/tree/preact-compat-react-19-raf

Opening transition is not working in Firefox with preact/compat - there is no transition visually.

By process of elimination I discovered that the problem was in the requestAnimationFrame call in src/hooks/use-transition-status.ts

Looks like, when Preact is used, requestAnimationFrame callback is called on same render tick that previous render.

Sorry if I use terms that are not applicable to Preact and its rendering model, I just don't know enough about the internals of Preact.

Steps to reproduce the behavior:

  1. Clone demo branch of repo with fresh Node.js (22+) installed
  2. npm i && npm run dev
  3. Try open modal in Firefox and see no opening transition

Expected behavior
I'm not sure if this is a problem or a feature of Preact or a feature of my source code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions