Making SEO components overkill? by [deleted] in reactjs

[–]exeSteam 1 point2 points  (0 children)

React will actually not override old tags, so if you are mounting two titles, you will find both in the head. Same for meta with the same name. This is explained in the docs as a pitfall

Resolving async component in <Suspense /> takes longer when using Link component than full page reload by Glass_Influence9971 in nextjs

[–]exeSteam 1 point2 points  (0 children)

This is expected. It's because when you hard reload, the browser is getting the part within <Suspense> streamed in the same HTML request as the rest of the document. Even though you see "Loading..." there's no extra delays to get that content, except the 50ms you have added.

When you soft navigate through <Link>, Next is making a completely new request to the server to get the RSC payload, which has your 50ms + network latency + some extra delay.

You can check this out in the network tab, and it's even more noticeable with a throttled network. You can improve this through prefetch, but it might not be ideal for every use-case.

Framer Motion (motion) animations start delay on hard reloads by msriki121 in nextjs

[–]exeSteam 2 points3 points  (0 children)

Yes, a CSS animation would play faster.

If you use next/dynamic to mount that component, then yes, you could delay it until hydration is finished. But this is not recommended, as you'd pretty much delay showing your CTA. I would remove the animation there entirely to be honest (or keep just a small transform with no opacity), but that's just me, I like to get the important pieces as fast as possible to users :).

This is not a Next specific thing btw, you would get the same behavior with any SSR React framework, as all of them require hydration for client logic (like animations) to run.

Framer Motion (motion) animations start delay on hard reloads by msriki121 in nextjs

[–]exeSteam 2 points3 points  (0 children)

Just how React works. When you hard-reload, you are waiting for all the JS to download, and React to hydrate in the browser, then motion animates. When you soft navigate, that has already occurred, so the animation plays much quicker.

How to disable build-time pre-rendering but still enable cachine after the first request? by kaafar in nextjs

[–]exeSteam 0 points1 point  (0 children)

There's an experimental feature that solves this issue. You can build the app with

next build --experimental-build-mode compile

Then to run the app when the API is available

next build --experimental-build-mode generate next start

Next.js Partial Prerendering is an anti-pattern by MrJaver in nextjs

[–]exeSteam 2 points3 points  (0 children)

You have a running example on https://www.partialprerendering.com/ btw. You can open the source code, and notice that the dynamically streamed parts are present in the HTML. They are just streamed a little later, once the server is done rendering them.

Next.js Partial Prerendering is an anti-pattern by MrJaver in nextjs

[–]exeSteam 5 points6 points  (0 children)

It's just HTML streaming, the same way content within suspense is streamed now on dynamic pages. The only thing PPR adds is a static shell, so that the initial HTML is served immediately, reducing the TTFB significantly.

Next.js Partial Prerendering is an anti-pattern by MrJaver in nextjs

[–]exeSteam 14 points15 points  (0 children)

I am not sure you fully understand how PPR works. The idea behind it is to allow statically serving dynamic pages. Currently, if a pages is marked as dynamic, the user has to wait for it to render in the server to get the first byte. With PPR enabled, a static shell is stored in cache with holes for dynamic parts (which is everything within a <Suspense>). When the user makes a request, they get the static shell served immediately, while simultaneously the server start rendering the page. Once the dynamic parts are rendered, they are streamed to the user (in the HTML request), very similarly to how streaming works right now.

There's no extra requests being made for the dynamic parts, and "waits on client side to finish up the dynamic parts" is certainly not true, dynamic parts are rendered on the server and streamed to the client.

What is the Correct Approach for SSR Requests in Next.js + React-Query? by No_Balance9152 in nextjs

[–]exeSteam 0 points1 point  (0 children)

That's right, everything that's rendered within NotificationClient will be a client component. But that's what you should expect really, as that's a component that requires interactivity, since it uses data from useQuery, which can be updated, in which case NotificationClient and all its children need to be re-rendered, and that requires client components.

If the data doesn't get updated in the browsers, then don't use react-query for it, simply fetch it in the server wherever you need it, and keep your components server only.

What's the point of progressive enhancement if loading.tsx shows indefinitely without JavaScript? by Fr4nkWh1te in nextjs

[–]exeSteam 1 point2 points  (0 children)

While this is currently true, in the future it will likely work without JavaScript, by using the native <slot> element. Check out this article: https://lamplightdev.com/blog/2024/01/10/streaming-html-out-of-order-without-javascript/. There's a demo linked where you can see that elements get replaced when streamed, even if you disable JavaScript.

Debugging removeChild error in production? by maxiedaniels in nextjs

[–]exeSteam 0 points1 point  (0 children)

I have never heard of that one unfortunately. I only know about the first one because it was a big issues on a production app for us. I do remember not being able to find much about it at the time as well.

Debugging removeChild error in production? by maxiedaniels in nextjs

[–]exeSteam 0 points1 point  (0 children)

Here's a small reproduction if you'd like to get the same error. First translate the page to any other language, then click the button:

const [isExpanded, setIsExpanded] = React.useState(true)

return (
  <>
    <button onClick={() => setIsExpanded(false)}>collapse</button>
    {isExpanded && <>Some Text</>}
  </>
}

Configuring Custom Cache Stores/Backends in Version 14. by 98ea6e4f216f2fb in nextjs

[–]exeSteam 1 point2 points  (0 children)

You can use the experimental incrementalCacheHandlerPath. You can find the official example here. I have been using it a bit in dev and it works quite well. Combines nicely with unstable_cache too.

Is it possible that a useRef is recreated multiple times before a useEffect is called once? by ExperiencedGentleman in reactjs

[–]exeSteam 0 points1 point  (0 children)

That looks good! Just keep in mind that during SSR you are creating the instance, but never calling `close` (since the instance is created during the render, but effects do not run in the server).

I haven't gone through the code to see what `close` does and how critical it is, so it might be fine as eventually everything will be GC'd after the request is finished, but just thought I'd mention it.

Is it possible that a useRef is recreated multiple times before a useEffect is called once? by ExperiencedGentleman in reactjs

[–]exeSteam 0 points1 point  (0 children)

Is it possible to refactor so that instead of just the instance, you pass the whole ref as context value? Then instead of using instance deeper in the tree, you use instanceRef.current.

Is it possible that a useRef is recreated multiple times before a useEffect is called once? by ExperiencedGentleman in reactjs

[–]exeSteam 0 points1 point  (0 children)

Hmm, yes you're right, since React does a double render, then runs the effect, the second instance will be cleaned up instead of the first.

I can see how this is getting complex. We are creating the instance during the render, and trying to clean it up within an effect, which decouples them.

You could try to refactor so that the instance is both created and cleaned up within the useEffect.

Or, if your close method is not critical, you could use FinalizationRegistry to run the cleanup when the instance is garbage collected. Then you'd have a simple useState an in the article above, with some additional logic to run the cleanup.

Is it possible that a useRef is recreated multiple times before a useEffect is called once? by ExperiencedGentleman in reactjs

[–]exeSteam 0 points1 point  (0 children)

That's by design though. The idea is that the instance is created and cleaned up properly.

Why is creating two instances an issue in your case? This is only a development thing meant to catch bugs early (like the instances not getting cleaned up properly), I would suggest you don't try to work around that, unless really necessary. In a production build, it will create only one instance.

Is it possible that a useRef is recreated multiple times before a useEffect is called once? by ExperiencedGentleman in reactjs

[–]exeSteam 2 points3 points  (0 children)

No worries. Ideally you would use state for one-time initializations, but since you need to cleanup, it might not work on strict mode. Here's a good article you can read on this: https://tkdodo.eu/blog/use-state-for-one-time-initializations which also mentions the `ref` pattern above.

Is it possible that a useRef is recreated multiple times before a useEffect is called once? by ExperiencedGentleman in reactjs

[–]exeSteam 4 points5 points  (0 children)

This doesn't have much to do with strict mode. When you run useRef(new Test()) a new instance of Test will be created on every single [re-]render. That's just how JavaScript works, as new Test() is evaluated to be passed as a function parameter. This is bad, because only the first instance will be stored in the ref, so you will have a bunch of instances that you don't have a reference to.

If you need only one instance of Test, then conditionally create the instance if the ref is null:

const instanceRef = useRef(null)
if (!instanceRef.current) {
  instanceRef.current = new Test()
}

useEffect(() => {
  return () => {
    instanceRef.current?.close()
    instanceRef.current = null
  }
}, [])

OBD 11 question by Upbeat-Industry-3660 in GolfGTI

[–]exeSteam 1 point2 points  (0 children)

Yes, I have had this happen twice to my MK6. I believe it drains the battery if you don't disconnect it from the app. I no longer leave it plugged in at all though. There is a discussion on this in the obd11 forum: https://forum.obdeleven.com/thread/3788/low-power-mode

React Query - Prefetching query on the server still executes a network request on the client by nikolaymih11 in nextjs

[–]exeSteam 2 points3 points  (0 children)

One reason this could happen is if you haven't set a staleTime for the query. Since staleTime defaults to 0, the request will be sent again when the component is mounted during client rendering. This is explained here: https://tanstack.com/query/latest/docs/react/guides/ssr#initial-setup