TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Making sense of React Server Components

118 点作者 joshwcomeau超过 1 年前

15 条评论

paxys超过 1 年前
The last decade of web dev can be summed up as:<p>– A bunch of smart Facebook engineers with unlimited funding decided to mess around and see just how much they could upend all the existing web paradigms, before finally concluding that conventional wisdom and the traditional server-side rendering model exist for a reason and make sense.<p>– The entire software industry decided that every new experiment by this above group was worth ripping out and rewriting their entire codebase over, whether it made sense for their needs or not and whether it actually made their product better or not.<p>I have not been too deep into the weeds of it myself but have been interacting with FE teams at my company enough to see what a charade it all is.<p>&quot;This React thing is cool, and everyone is talking about it. Let&#x27;s move some of our existing JS components over to it and see how things turns out.&quot;<p>&quot;We need to do a top-down rewrite of the entire app in React.&quot;<p>&quot;We&#x27;re going to need the infra team to set up a GraphQL API layer for us. It can&#x27;t be that hard, right?&quot;<p>&quot;Hmm, initial page loads are too slow. Hey infra team, can you set up a render farm of Node.js servers so we can do SSR?&quot;<p>&quot;Whoa, functional components are cool! We need to do another top-down rewrite and get rid of all the silly classes.&quot;<p>&quot;We have a small team dedicated to investigating server components, and if the prototype looks good then we&#x27;ll switch over to Next.js and rewrite our FE + API stack.&quot;<p>I&#x27;m sure my company wasn&#x27;t the only one that caught this virus. I shudder to think just how much money and productivity has been wasted industry-wide over the obsession with this framework.
评论 #37413242 未加载
评论 #37414460 未加载
评论 #37413276 未加载
评论 #37415779 未加载
评论 #37413528 未加载
评论 #37418891 未加载
megaman821超过 1 年前
The more features React adds the less I end up using React. The new additions are just so inelegant, and don&#x27;t fit my brain. The function useEffect has so many caveats and such a terrible API. A magic &quot;use client&quot; string at the top of a file is just ridiculous. React code is nearly impossible to understand and write without extensive external documentation now. I feel sad for the future developer that has to modify this type of code ten years from now; I hope Google is good at searching decade old documentation to figure out what the hell is going on in old React code.
评论 #37410887 未加载
评论 #37408805 未加载
评论 #37410529 未加载
评论 #37413302 未加载
评论 #37408692 未加载
评论 #37408720 未加载
评论 #37410130 未加载
评论 #37409730 未加载
halfmatthalfcat超过 1 年前
It&#x27;s annoying that the React team announced Server Components without a well defined spec, the wire protocol most significantly. Instead, it&#x27;s a cabal between the React team and Vercel which obviously is going to give them an inherent advantage and probably steer things in their favor, rather than the broader React ecosystem as a whole.
评论 #37435523 未加载
评论 #37409093 未加载
MPiccinato超过 1 年前
I will have to give this article a more full read rather than just a skim, but...<p>I am left with such confusion as to how React&#x2F;Next arrived at this solution. `useEffect` didn&#x27;t run on the server when doing SSR, great, easy enough to understand. Now several common hooks don&#x27;t run on the server because they are considered interactive? And it isn&#x27;t that they won&#x27;t run, their initial pass in most cases doesn&#x27;t do anything, it is that Next now yells at you for having a `useState` hook in a &quot;Server Component&quot;.<p>I would like to write a component, not have to think about where it is running in most cases, and go on with my day. I mostly use React for large SPAs and have adopted Next for doing SSR on the few pages that I needed it for (SEO, etc).
评论 #37410939 未加载
评论 #37415035 未加载
评论 #37436314 未加载
xixixao超过 1 年前
&gt; In order for this to work, we&#x27;d need to be able to give React a chunk of code that it runs exclusively on the server, to do the database query<p>This is not true&#x2F;it’s misleading. What you need is to be able to fetch on the server, and hydrate on the client using data from the server. This is possible with SSR and injecting into the React stream, using isomorphic (client) components.<p>The article is great, but the reasons for RSC are more subtle&#x2F;complicated than the flow of the article would imply.
评论 #37408525 未加载
benatkin超过 1 年前
&gt; This tutorial is written primarily for developers who are already using React<p>Also good for those moving away from React, since we understand React too. Probably won&#x27;t change it, but may give us things to look for in our new frameworks. A former coworker who was <i>really</i> into React just switched to Flutter.
评论 #37408037 未加载
rabuse超过 1 年前
Hilarious that the industry is going full-circle back to server rendered pages.
评论 #37435700 未加载
评论 #37412006 未加载
评论 #37408994 未加载
DanielHB超过 1 年前
A lot of people are complaining about NextJS + Vercel lock-in<p>RSC locks you into their hosting solution and the way they suggest you to use it also locks you into NextJS way of building your backend data layer (ie PHP&#x2F;JSP&#x2F;ASP-like with our without MVC)<p>But their routing things locks you into NextJS as a framework. Just remember how much people complained about migrating from react-router v4 to v5 (or was it v5 to v6?). Migrating from a routing solution is a huge pain in the ass. I am still unconvinced that file-system based routing is better. It is at best a replacement for lack of guidelines in most routing libs on how to organise your components for routing.<p>I am also very weary of anything that takes over the bundler, bundling is a hard problem and just outsourcing it is asking for trouble. But I understand why a lot of people don&#x27;t want to deal with it, it takes a huge codebase for bundling to become a big issue.<p>I am looking forward to Bun: <a href="https:&#x2F;&#x2F;bun.sh&#x2F;" rel="nofollow noreferrer">https:&#x2F;&#x2F;bun.sh&#x2F;</a><p>Which promises to reduce the tooling headaches to get a project going without using a bunch of frameworks. Their bundler though is still nowhere near ready so I wouldn&#x27;t recommend it for frontend projects yet. Using Bun just to run nextjs&#x2F;webpack&#x2F;whatever on top of it also doesn&#x27;t seem like a good solution to me.<p>Bun might support RSC in the future, but in my opinion RSC is a very specialised tool to be used only in a few critical places in your code and it is scary how Vercel is pushing for it so hard in their docs. You have to remember that the average new frontend developer now uses &quot;create-next-app&quot; not &quot;create-react-app&quot; and is introduced to RSC right away
评论 #37436392 未加载
Gunax超过 1 年前
Server side rendering isnt special any more:<p><a href="https:&#x2F;&#x2F;joshcollinsworth.com&#x2F;blog&#x2F;antiquated-react#server-side-rendering-isnt-special-anymore" rel="nofollow noreferrer">https:&#x2F;&#x2F;joshcollinsworth.com&#x2F;blog&#x2F;antiquated-react#server-si...</a><p>This blog was posted to HN a few weeks ago. The author does a really good job of summarizing React&#x27;s relationship with the rest of the SPA ecosystem.
bdcravens超过 1 年前
so ... ColdFusion custom tags?
评论 #37408445 未加载
评论 #37415123 未加载
foota超过 1 年前
This is my first time really reading about them, I&#x27;d assumed they&#x27;d do some ASPX style interactivity where server components updates on the server and send back html, it&#x27;s interesting that they haven&#x27;t tried to go for something like that, meaning this is a lot more limited in scope in some ways than I&#x27;d thought.
评论 #37409056 未加载
idosh超过 1 年前
How does it handle flaky connection or even offline scenario? How does it work with service worker?
lioeters超过 1 年前
&gt; As I write this, there&#x27;s only one way to start using React Server Components, and that&#x27;s with Next.js 13.4+<p>I don&#x27;t understand how this is acceptable to the React user community, that only Vercel gets to be in this privileged position. Why did they not include other companies, or the users themselves, in the discussion and development of this feature.<p>&gt; Since Server Components are a new React feature, third-party packages and providers in the ecosystem are just beginning to add the &quot;use client&quot; directive to components that use client-only features like useState, useEffect, and createContext.<p>&gt; Today, many components from npm packages that use client-only features do not yet have the directive. These third-party components will work as expected within Client Components since they have the &quot;use client&quot; directive, but they won&#x27;t work within Server Components.<p>The arrogance of expecting all third-party packages, React-related or not, to buy into the &quot;use client&quot; directive. A humbler approach would have been a &quot;use server&quot; directive to opt-in to this behavior, instead of expecting the <i>entire rest of the ecosystem</i> to adapt to it.
评论 #37408963 未加载
评论 #37409014 未加载
评论 #37436655 未加载
评论 #37408709 未加载
评论 #37408894 未加载
评论 #37408910 未加载
TheGeminon超过 1 年前
&gt; Instead of bouncing back and forth between the client and server, we do our database query as part of the initial request, sending the fully-populated UI straight to the user.<p>&gt; But hm, how exactly would we do this?<p>Couldn&#x27;t help but chuckle. What mysterious technology could allow us to send an entire fully-populated UI over the web?
评论 #37408219 未加载
评论 #37408183 未加载
评论 #37408736 未加载
评论 #37408250 未加载
rco8786超过 1 年前
I&#x27;ll do what I did the last time one of these articles popped up. Word counts:<p>complex: 2<p>confusing: 3
评论 #37408917 未加载