-
-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot import async components: Undefined component passed to createElement() #1293
Comments
Update: |
I assume that, while this warning shows up in your console, the component does render? As that is what I can reproduce. One solution could be to use Lazy & Suspense. While marked as experimental, it does seem to suppress that warning.
|
It actually prevents other things from rendering. I can't reproduce it now but it tried it in a bigger application. I've also noticed that downgrading to |
Found a better way to reproduce this: // src/index.js
import Hello from './components/async/Hello'
export default function App() {
return <>
<Hello />
<div>This won't be rendered.</div>
</>
} But if you use an element instead of fragments the error will be gone. |
@hkh12 can you just reproduce this in a repo and share if possible? |
Awesome, thanks. Will look into it now. |
I finally (FINALLY) found a solution for #1293, #1308, etc etc. This doesn't use DOM hacks or anything - it just crawls up the tree of VNodes and performs a Depth-First-Search backwards from the position of AsyncComponent in order to find the most recently hydrated DOM element. Essentially, the first populated `vnode._dom` reference it finds is guaranteed to be the previous sibling of the parent element AsyncComponent is about to get rendered into. As long as AsyncComponent isn't being used load a component that renders a Fragment, the nextSibling of that discovered element is the exact node Preact will try to hydrate. In the case of an AsyncComponent wrapping a Fragment, only the first Fragment child will be hydrated. This means the remaining children will have the flicker effect, but that's pretty reasonable: ```js // app.js import Foo from 'async!./foo'; export default () => <div><Foo /></div> // foo.js export default () => <Fragment> <h1>Hello</h1> <p>world!</p> // will be culled+reinserted during hydration </Fragment> ```
* Fix async-loader for Preact X I finally (FINALLY) found a solution for #1293, #1308, etc etc. This doesn't use DOM hacks or anything - it just crawls up the tree of VNodes and performs a Depth-First-Search backwards from the position of AsyncComponent in order to find the most recently hydrated DOM element. Essentially, the first populated `vnode._dom` reference it finds is guaranteed to be the previous sibling of the parent element AsyncComponent is about to get rendered into. As long as AsyncComponent isn't being used load a component that renders a Fragment, the nextSibling of that discovered element is the exact node Preact will try to hydrate. In the case of an AsyncComponent wrapping a Fragment, only the first Fragment child will be hydrated. This means the remaining children will have the flicker effect, but that's pretty reasonable: ```js // app.js import Foo from 'async!./foo'; export default () => <div><Foo /></div> // foo.js export default () => <Fragment> <h1>Hello</h1> <p>world!</p> // will be culled+reinserted during hydration </Fragment> ``` * Stop searching if we hit an element parent Co-authored-by: Anup <allamsetty.anup@gmail.com>
@hkh12 this is resolved in the latest rc (3.0.0-rc.17) today. Feel free to re-open if you are still facing the issue 🙂 |
Still facing the issue. I committed the updates to https://github.com/hkh12/preact-cli-bug-1293 |
facing this issue in preact:10.4.7, preact-cli: 3.0.1. downgrading preact CLI helped. |
also facing this issue:
trying to replicate it in a codesandbox but can't seem to |
@FranciscoG did you find a resolution/or the issue? I'm running into this with the following packages, but like you in a sandbox it works. I've tried multiple node versions and started with a clean package-lock file and clean node_modules direction to no avail.
|
I found that the resolution for me was to not use a second component declared within the same file and only to use imported components.... not sure why this was an issue though. |
I am just getting started with Preact and I ran into this error when I tried to use my class component 🐞Uncaught Error: Invalid type passed to createElement(): [object Object] import { Component, ComponentChild, RenderableProps } from "preact";
interface ParameterTypesProps {
}
interface ParameterTypesState {
}
export class ParameterTypesPanel extends Component<ParameterTypesProps, ParameterTypesState> {
constructor() {
super({});
this.state = {};
}
render(props?: RenderableProps<ParameterTypesProps, any>, state?: Readonly<ParameterTypesState>, context?: any): ComponentChild {
return <div></div>;
}
} index.tsx: export function App() {
return (
<LocationProvider>
<Header />
<main>
<Router>
<Route path='/' component={Home} />
<Route path='/ParameterTypes' component={new ParameterTypesPanel} />
<Route default component={NotFound} />
</Router>
</main>
</LocationProvider>
);
} Does someone by chance have an idea what is wrong here? And why is there no diagnostics information coming from Preact in the error message. Stack trace is not visible in browser console |
@hinst Please switch to a supported tool, like a Vite via Edit: Never invoke/create components directly. Switch |
Do you want to request a feature or report a bug?
It's a bug.
What is the current behaviour?
I'm trying to load a component from
src/components/async
directory, and get this error:If the current behaviour is a bug, please provide the steps to reproduce.
What is the expected behaviour?
Load the component
Hello
as an async component.Please mention other relevant information.
Please paste the results of
preact info
here.The text was updated successfully, but these errors were encountered: