Comments (4)
@pedroalmeida415 "use client" does not mean "client only", it means "send all the JS to the client".
In a nutshell, you are trying to use the library as one would in a plain React application.
Try using useSuspenseQuery
from react-query
. You need to use hooks; if you only want to fetch in the browser, you would run the fetch inside useEffect
and then suspend from there. Or you can save yourself a lot of effort and use react-query
.
Or better yet, use a server component and let Next build your page statically: https://stackblitz.com/edit/stackblitz-starters-jcwjjf?file=app%2Fpage.tsx
from next.js.
It seems like Next.js really doesn't like that I use the suspense feature manually on a Client Page route, and it runs the request in a server environment even though it's not
Considering the following route structure, where both Page and Home are client components:
// app/page.tsx
<Suspense fallback={<div'>loading...</div>}>
<Home />
</Suspense>
Inside <Home />
I'm fetching data that will be used to display the contents of the page (it can't be a server component)
The fecthing goes like this:
// suspend() is using suspend-react library - I also tried without it (just throwing a Promise and managing state manually)
// AND with react-query, both yield the same error
async function getMultipliers() {
const res = await fetch(`/multipliers.bin`)
const buffer = await res.arrayBuffer()
const decompressedStreamBuffer = LZMA.decompressFile(buffer)
const rawBytes: Uint8Array = decompressedStreamBuffer.toUint8Array()
return rawBytes
}
const multipliersArray = suspend(async () => await getMultipliers(), [])
This correctly suspends the component and displays the fallback in the <Suspense />
tag, but I get an error in the console:
react-dom.development.js:17497 Uncaught
Error: Failed to parse URL from /positions.bin
at updateDehydratedSuspenseComponent (react-dom.development.js:17497:1)
at updateSuspenseComponent (react-dom.development.js:17193:1)
at beginWork$1 (react-dom.development.js:18509:1)
at beginWork (react-dom.development.js:26927:1)
at performUnitOfWork (react-dom.development.js:25748:1)
at workLoopSync (react-dom.development.js:25464:1)
at renderRootSync (react-dom.development.js:25419:1)
at performConcurrentWorkOnRoot (react-dom.development.js:24504:1)
at workLoop (scheduler.development.js:256:1)
at flushWork (scheduler.development.js:225:1)
at MessagePort.performWorkUntilDeadline (scheduler.development.js:534:1)
Now, I managed to hack my way around this error by dinamycally importing the <Home />
component and explicitly setting the ssr to false in the options:
const Home = dynamic(() => import('@/components/home/home').then((mod) => mod.Home), {
ssr: false,
loading: () => <div>loading...</div>,
})
With this, the error goes away, but I'm left wondering why it even happened in the first case
This <Home />
component shouldn't even exist, it should just be the content of the app/page.tsx
component, which combined with an app/loading.tsx
component gives the exact structure needed to use suspense, so I'm convinced there's something wrong going on here
from next.js.
Accidentaly pressed the hotkey to comment and close, my bad
from next.js.
"use client"
only means the code will be sent to the browser, it does not skip server rendering.
from next.js.
Related Issues (20)
- `unstable_cache` with certain value of revalidation interval persisted correctly in production build
- Failed To Load SWC binary for win32/x64 HOT 1
- Click the browser forward and back, and getServerSideProps does not re-execute HOT 20
- next.config.ts does not support top-level-await
- Failed to load SWC binary for win32/x64
- Custom cache handler with dynamic route + static params always shows 404 page HOT 2
- create-next-app (canary): Import of *.module.scss in Client Component causes `__webpack_require__.n is not a function` crash HOT 3
- Catch-all route also catches static assets
- basePath not creating structure correctly when output set to export HOT 3
- Localized Sitemap Doesn't Work HOT 1
- Localized Sitemap Does Not Work
- Cookies set in middleware missing on server actions HOT 1
- basePath not creating structure correctly when output set to export
- [typedRoutes] mdx pages in app router are omitted from the Route type during `next build`
- Failed to load SWC Binary for android-arm64
- r is not a function when wrapping API route with a function HOT 4
- Docs: Incorrect version history for sitemap adding changeFrequency and priority attributes to sitemaps
- next.config logging option does not log in runtime edge
- <Link> component make the page refresh new request ??
- Module css is not working with Parallel Route
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from next.js.