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.

[10.0.0-alpha.2] Rerender necessary when importing component using React.forwardRef and Fragments

See original GitHub issue

We have a project written in Preact that is referencing a component from another library (written with React 16) that does not render at all on first render (it will appear if I force a rerender). There is no error or stacktrace. The component we reference looks like this:

import React from "react";

const TheComponent = React.forwardRef((props, ref) => {
  const { ...rest } = props;

  return (
    <OtherComponent {..rest} />
});

export default TheComponent;

The OtherComponent looks like this:

import React, { forwardRef, Fragment } from "react";

const OtherComponent= forwardRef(
  ({  ...otherProps }, ref) => (
    <Fragment key="">
      <input type={type} ref={ref} {...otherProps} />
    </Fragment>
  )
);
export default OtherComponent;

Is this a known issue with Preact X? (which we are now on! 🎉 ) What is the most reliable work-around for this right now?

We thought it might be related to Fragments, because of the reference to OtherComponent, which doesn’t show up on the first render. I tried using the workaround from here: https://github.com/developit/preact/issues/946#issuecomment-353151850 at the top of our file. If I switch back to React, it works fine, but I am definitely a fan of the small bundle with Preact so really want to make this work.

"preact": "10.0.0-alpha.2",
"preact-compat": "3.18.4",
"preact-redux": "2.0.3",

I will try to see if I can replicate in a sandbox, but if there are initial thoughts I would appreciate them!

EDIT: Also if I meddle in node_modules and switch the Fragment to a div it renders fine-- another hint this has to do with Preact and Fragments

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
marvinhagemeistercommented, Mar 27, 2019

Thanks for creating the issue 👍 I’m wondering if this is caused by mixing preact-compat which is written for Preact 8 with Preact X. Maybe just aliasing react to preact/compat instead of preact-compat will resolve the issue 🎉

1reaction
JoviDeCroockcommented, Mar 28, 2019

I do not seem to have any issues: https://codesandbox.io/s/jvqopz0z05

Read more comments on GitHub >

github_iconTop Results From Across the Web

[10.0.0-alpha.2] Rerender necessary when importing ... - GitHub
We have a project written in Preact that is referencing a component from another library (written with React 16) that does not render...
Read more >
[10.0.0-alpha.2] Rerender necessary when importing component ...
We have a project written in Preact that is referencing a component from another library (written with React 16) that does not render...
Read more >
React memo allowing re-rendering to forwardRef
This has nothing to do with the ref. LzSearch is rerendering because the onUpdate prop is changing. MyComp will need to use useCallback...
Read more >
How and when to force a React component to re-render
React automatically re-renders components, but what happens when a component is not updating as expected? Find out what you can do here.
Read more >
material-ui/core/CHANGELOG.md - UNPKG
The best support for React 17 will be found in Material-UI v5. ... with the theme and the lab components, TypeScript users need...
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