Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Regression: textarea ‘jumps’ after initial load #95

Closed
humphreybc opened this issue Jan 23, 2018 · 5 comments
Closed

Regression: textarea ‘jumps’ after initial load #95

humphreybc opened this issue Jan 23, 2018 · 5 comments
Labels

Comments

@humphreybc
Copy link
Contributor

I just upgraded from 0.4.9 to 3.0.2 and noticed a change in behavior. Now, when the page loads, the textarea will noticeably ‘jump’ to the correct height, pushing everything below it down the page. Before, the textarea was the correct height on initial load, so there was no jump.

Here's a gif with the CPU throttled in dev tools to try and emphasize the issue for the purpose of recording. The first tab is the latest version (3.0.2) and the second tab is the old version. If you download the gif and look at frame 70, you can see the moment where the title is loaded at the wrong height before jumping to the correct height in the next frame.

autoresize-grow

Here's the relevant code (simplified to reproduction case):

import * as React from "react";
import TextareaAutosize from "react-autosize-textarea";
import { style } from "typestyle";

interface Props {
  defaultValue?: string;
}

export class NoteTitle extends React.Component<Props> {
  public render() {
    return <TextareaAutosize className={className} defaultValue={this.props.defaultValue} />;
  }
}

const className = style({
  border: 0,
  fontSize: "40px",
  fontWeight: 600,
  lineHeight: "48px",
  margin: 0,
  overflow: "hidden",
  outline: 0,
  resize: "none",
  width: "100%"
});
@FrancescoCioria
Copy link
Contributor

I think I know the reason: after #71 we're always initializing autosize asynchronously by wrapping it in a setTimeout.

(The issue was opened after the discussion in #69)

The only idea I can come up with to make everyone happy is to optionally wrap it in a setTimeout based on some kind of prop.

@apuntovanini
Copy link

@FrancescoCioria confirmed it changed behaviour, I think passing a prop could make everyone happy. How about an async boolean prop?

@FrancescoCioria
Copy link
Contributor

How about an async boolean prop?

sounds good 👍

I would still force it to be async when (typeof maxRows === 'number') as it was before, otherwise the maxRows feature doesn't work correctly

renchap added a commit to renchap/react-autosize-textarea that referenced this issue Jun 16, 2018
Adds a new `async` prop to force async initialization, as proposed in buildo#95.

Async initialization will make your page "jump" when the component appears, as it will first be rendered with the normal size, then resized to content. But async init is only needed when using StyledComponents (see buildo#71) or when `maxRows` is set, so let the user decide to enable it.

Fixes buildo#95
@renchap
Copy link
Contributor

renchap commented Jun 16, 2018

I sent a PR fixing this: #103

renchap added a commit to renchap/react-autosize-textarea that referenced this issue Jun 16, 2018
Adds a new `async` prop to force async initialization, as proposed in buildo#95.

Async initialization will make your page "jump" when the component appears, as it will first be rendered with the normal size, then resized to content. But async init is only needed when using StyledComponents (see buildo#71) or when `maxRows` is set, so let the user decide to enable it.

Fixes buildo#95
@FrancescoCioria
Copy link
Contributor

I published the fixed in the new major 4.0.0 (as this fix is breaking for people using StyledComponents)

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

No branches or pull requests

4 participants