question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react-transition-group "-enter(-active)" doesn't work with Preact X

See original GitHub issue

react-transition-group is partially not working with Preact X.

I’ve created a Preact project with preact-cli by preact create typescript test (--yarn) (with typescript template), installed preact@next and upgraded other packages:

$ yarn add preact@next
$ yarn upgrade
$ yarn remove preact-router
$ yarn add react-router react-router-dom @types/react-router @types/react-router-dom
$ yarn add react-transition-group @types/react-transition-group

After replacing preact-router by react-router(-dom), I’ve changed some codes accordingly.

app.tsx:

import { Component, h } from "preact";
import { BrowserRouter as Router, Route, Switch } from "react-router-dom";
import { CSSTransition, TransitionGroup } from "react-transition-group";

import Home from "../routes/home";
import Profile from "../routes/profile";
import Header from "./header";

if ((module as any).hot) {
    // tslint:disable-next-line:no-var-requires
    require("preact/debug");
}

export default class App extends Component {
    public currentUrl?: string;

    public render() {
        return (
            <div id="app">
                <Router>
                    <Header />
                    <Route
                        render={({ location }) => {
                            return (
                                <TransitionGroup>
                                    <CSSTransition
                                        timeout={6000}
                                        classNames="page"
                                        key={location.key}
                                    >
                                        <Switch location={location}>
                                            <Route
                                                exact
                                                path="/"
                                                component={Home as any}
                                            />
                                            <Route
                                                exact
                                                path="/profile/"
                                                component={
                                                    (() => (
                                                        <Profile user="me" />
                                                    )) as any
                                                }
                                            />
                                            <Route
                                                path="/profile/:user"
                                                component={
                                                    (({ match }: any) => (
                                                        <Profile
                                                            user={
                                                                match.params
                                                                    .user
                                                            }
                                                        />
                                                    )) as any
                                                }
                                            />
                                        </Switch>
                                    </CSSTransition>
                                </TransitionGroup>
                            );
                        }}
                    />
                </Router>
            </div>
        );
    }
}

Then -exit(-active) works while -enter(-active) doesn’t.

Is there anything I’m missing?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
marvinhagemeistercommented, Aug 11, 2019

Okay, I think I have a good understanding of what’s happening here. The problem is that componentDidMount is called before the DOM has been updated completely. It’s a difficult problem and I have the feeling that this is not just a small fix, but a more involving issue. Not sure if that would make it into the initial X release.

1reaction
marvinhagemeistercommented, Aug 11, 2019

Thanks for the two repos 🎉 They’re awesome and help a lot in narrowing the issue down. So far I was able to step through the source of react-transition-group and it fails to apply the enter-* classes. This happens because findDOMNode() returns null and not the expected DOM node. The entering classes are set inside the componentDidMount lifecycle hook. In Preact speak we’re not setting _dom and c.base correctly there. Will need to investigate further.

Read more comments on GitHub >

github_iconTop Results From Across the Web

I cannot get React Transition Group to work. No enter or leave ...
When using CSSTransition for routes, you don't want to use a Switch or a TransitionGroup . You want to put the CSSTransition in...
Read more >
Switching to Preact (from React)
Everything you need to know to switch from React to Preact.
Read more >
How To Implement Smooth Transitions in React | by Rajat S
In this post, you will see how to use the React-Transition-Group library to implement smoother transitions. In the end, you will be able...
Read more >
react-transition-group nextjs Code Example
Attempted import error: 'Map' is not exported from 'react-leaflet' (imported as 'LeafletMap'). ... Can i open native video playback for both ( ...
Read more >
What is the difference between the appear, enter, exit events ...
Coding example for the question React Transition Group: What is the difference between the appear, enter, exit events and the enter, active done...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found