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.

Element ref behavior differs in development and production for initial render with new CSS support

See original GitHub issue

Bug report

Describe the bug

After updating to next@9.2 it seems that the refs are not being created during server-side render in development mode. Everything works fine after building to production, also everything works fine when mounting that component client-side. Also, everything works fine pre 9.2. Disclaimer: I may be wrong with my conclusion of what is really the cause of the bug. It may as well be with how I am rendering those components.

To Reproduce

My code: (this is yet to be refactored to hooks).

class ScheduleComponent extends React.Component {
  schedule = React.createRef();

  state = {
    visibility: 'hidden',
    width: 1240,
    leftBond: moment()
      .subtract(7, 'days')
      .startOf('day'),
    rightBond: moment()
      .add(23, 'days')
      .startOf('day'),
  };

  componentDidMount() {
    this.setState({
      width: this.schedule.current.scrollWidth,
      visibility: 'visible',
    });
    window.addEventListener('resize', this.resize);
  }

  componentWillUnmount() {
    window.removeEventListener('resize', this.resize);
  }

  resize = () => {
    this.setState({ width: this.schedule.current.scrollWidth });
  };

Expected behavior

Refs should be created during server-side render in dev mode.

Screenshots

What’s happening during server-side render. The elements with month names and year should be already rendered. They render only in production or during client-side mounting or after firing the resize function as you can see on the gif.

Peek 2020-01-19 19-33

System information

  • OS: Ubuntu 18.04.3
  • Browser: Firefox, Chrome
  • Version of Next.js: 9.2

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
JarrodMFleschcommented, Jan 19, 2020

Haha! I was literally just going to create this issue!

Here are two sandbox links to show the reproducible issue.

Does not work 9.2.0 Does work 9.1.7

1reaction
JarrodMFleschcommented, Jan 20, 2020

This should be resolved with #10164 and available in Next.js >= v9.2.1-canary.4

You guys rock.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Element ref behavior differs in development and production for ...
Element ref behavior differs in development and production for initial render with new CSS support #10163.
Read more >
Handling common HTML and CSS problems - MDN Web Docs
Basically, it is a matter of checking whether your HTML and CSS code is well formed and doesn't contain any syntax errors. Note:...
Read more >
Strict Mode - React
Strict mode checks are run in development mode only; they do not impact the production build. You can enable strict mode for any...
Read more >
Frequently Asked Questions - Material UI - MUI
How can I access the DOM element? All MUI components that should render something in the DOM forward their ref to the underlying...
Read more >
How To Debug React Components Using React Developer ...
When you open the console, you'll find two new tabs: Components and ... You activated the tools on both a production and a...
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