Suspense / lazy combined with import
?
#4060
kurtbuilds
started this conversation in
General
Replies: 1 comment 5 replies
-
I think you got a bit confused as to how I think what you're looking for is this: // lazy() returns a component
const LazyComponent = lazy(() => import('./path/to/my/file.js'));
// Usage, remember lazy() returns a component
<LazyComponent /> |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm trying to do code splitting, and I can't figure out how to make it work. I'm not up to date on a lot of frontend, so please tell me if I'm approaching this the wrong way.
The longer context is that I want to use vite & react to create a blog (almost entirely SSG, but with frontend javascript that might fetch related articles, comments, etc.). Ideally, I want to have the same stack as what I'd use for a SPA, so that whether I'm working on the blog or SPA, the code patterns don't change, and I can reuse components between the two.
I created a directory
blog/
that contains a bunch of.mdx
files. I then created:I'm using
wouter-preact
for client-side routing. I created a componentRoutes
like this:And this works as desired. I have additional scripts for an
entry-server.tsx
andprerender.js
that does the SSG rendering, and those work as desired.However, this doesn't actually achieve code splitting, because of
{eager: true}
. Ok, let's remove that and see what happens:And update the routes to use suspense:
With this, there's no error shown, either in browser or with
vite
, but nothing shows on the page either. It's blank.If I try different calling patterns, they all come back with different errors:
gives
This other one:
gives:
I'm using:
Beta Was this translation helpful? Give feedback.
All reactions