Replies: 11 comments 3 replies
-
It is a problem. |
Beta Was this translation helpful? Give feedback.
-
Did you solve the problem ? I have the same issue too and I have no idea how to fix it. It seems @loadable/component only works under webpack. |
Beta Was this translation helpful? Give feedback.
-
Hi, maybe you could workaround it using some thing like this: import { lazy, Suspense } from 'react'
const loadable = (factory: Parameters<typeof lazy>[0]) => () => {
const Component = lazy(factory);
return (
<Suspense fallback={<p>Loading...</p>}>
<Component />
</Suspense>
);
};
const Login = loadable(() => import("./pages/login"));
function App() {
return (
<Router>
<Routes>
<Route path={'/login'} element={<Login />}
</Routes>
</Router>
);
} |
Beta Was this translation helpful? Give feedback.
-
Is this possibly a replacement for the code-splitting functionality of loadable-components? https://github.com/sanyuan0704/vite-plugin-chunk-split |
Beta Was this translation helpful? Give feedback.
-
any fix? |
Beta Was this translation helpful? Give feedback.
-
Can I use @loadable/component's Full dynamic import feature with Vite? This works for me:
but this doesn't:
|
Beta Was this translation helpful? Give feedback.
-
React.createElement(loadable(() => import( |
Beta Was this translation helpful? Give feedback.
-
loadable-components only supports Webpack and therefore loadable-components cannot be used with Vite. |
Beta Was this translation helpful? Give feedback.
-
so, any way to solve this ? |
Beta Was this translation helpful? Give feedback.
-
Are we sure that loadable-components is actually necessary with Vite? Per this issue it seems that simply using React.lazy and dynamic imports might be sufficient, meaning that loadable-components isn't necessary anymore. See for instance https://vitejs.dev/guide/features#async-chunk-loading-optimization and https://rollupjs.org/tutorial/#code-splitting |
Beta Was this translation helpful? Give feedback.
-
React.lazy works in Vite but it has some drawbacks if using it as a replacement for loadable-components on server rendered pages. With React.lazy on server rendered pages, the stylesheets for the lazy modules will not be in the initial HTML, causing a Flash Of Unstyled Content (FOUC) on the page, and there will be no preloading of JS modules adding some significant startup time to your app. The vite-preload plugin solves this https://github.com/wille/vite-preload?tab=readme-ov-file#migrating-from-loadable-components |
Beta Was this translation helpful? Give feedback.
-
I've got a few components that are dynamically loaded with @loadable/component like so:
This seems to work fine when run on the client. With SSR - it doesn't get rendered. I tried using:
But this depends on
@loadable/webpack-plugin
to work. Is there a way to achieve something similar for dynamic react components under Vite that's compatible with SSR?Beta Was this translation helpful? Give feedback.
All reactions