Skip to content

Commit 9797ac8

Browse files
committed
Ran read-next to generate related examples
1 parent 1b00060 commit 9797ac8

41 files changed

Lines changed: 265 additions & 19 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

read-next/contentHashes.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"errors/error-boundary": "a28930e6e998da180dd78f729efd3c4555edfe9bb6437a3dbe873c73ffebbd55",
3+
"errors/error-tsx": "40b7c0e8e2881257d82eb5aa3900516a22b54642b67f266acfa071c001e3be27",
4+
"errors/no-handling": "4c56a26c30ea779bc670ab8aedb17e23e0110ff21335f12ab41586ef6b608fbf",
5+
"errors/reset": "6ed5bc1c2652be7ec4bb9af0b495f5f7cb4cbf20b4e27fff95896f3e18f1c8fb",
6+
"errors/reset-boundary": "ed0c33076fe11eccb236ddedd529bf4ad64b4d0fcd951f7caf4e12ff25ae246f",
7+
"pages/fast/no-suspense": "aabfbbcb06e55b3ca3be1a78d20b4226840bf94ed6a816a6e66930ff139c2fa1",
8+
"pages/slow/component-suspense": "bbabb039d57b3b2ac15c382f2a6a49603572b62bd95b55d870ffa90965e728f8",
9+
"pages/slow/no-suspense": "413a2fa2e9212956a0fe3286b9184e37d1d262f68c1c0c4392348bc6e1bc0742",
10+
"pages/slow/page-suspense": "9270bb130ee969cad005af46f5c26881be7d5aa49f011f03dca7f5d8aea4dbe5",
11+
"promises/rejected": "ba10258823764f32bd2bd6fa63e01a893aad91573965357a3e08973f6f0971be",
12+
"promises/rejected-handled": "a719139f62ee258a2691bb3172f751dc6e3bf7b190adeb8c8fd11148dc130ab4",
13+
"promises/rendering-components": "15b925595e3691928fbe8fcd648cda05f08dbac0200e78dd73343a1c5160a53c",
14+
"promises/resolved": "144811c5f5b6d58316f0c2055dff67b9e21f8e328bc061becd1c535182a67810",
15+
"promises/various-datatypes": "3652032eea834cb0ea9987ddb9245746ff0074f2c4bf6e0e844fb68a2d8f9783",
16+
"server-actions/form-status": "9d6816a2ba1ed58163ab333e4f5f375e73b583d84144d5701ac21a6814c8a748",
17+
"server-actions/form-zod-validation": "2bd84505f585e103c382aeaca4c463297d4a53b15f7ca7c73f7b088152f44858",
18+
"server-actions/simple-form": "174e36f3431e63132aaaa71eac82eadfd873ed6fcc9a94b5891f49dbf3e8171a",
19+
"static-pages/server-client": "5471d83cd9953b476e9e079bf27a748afa12c3b0fcaf6f8d9458e6ff08eb4645",
20+
"static-pages/server-only": "1084284a0df301ba5d376b460258ae5e5c6757ab1e56f227b8566881dc035482"
21+
}

read-next/docstore.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

read-next/faiss.index

114 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This example illustrates the use of an explicit error boundary in React Server Components to handle errors thrown by a server component. It highlights that the implementation is similar to client components, with the key distinction being that the error boundary itself is a server component. The example utilizes the `react-error-boundary` library to create the error boundary, although it notes that developers can also create their own custom error boundaries.
2+
3+
The provided code defines a `PageWithBoundary` component that includes an `ErrorBoundary` wrapping an `ErrorComponent`. When the `ErrorComponent` throws an error, the `ErrorBoundary` catches it and renders a fallback component, `ErrorFallback`, which displays an error message. This approach enhances user experience by providing a clear indication of an error, rather than showing a generic error or nothing at all.
4+
5+
Overall, this example serves as a practical demonstration of error handling in React Server Components, emphasizing the importance of user-friendly error management.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This example demonstrates how to handle errors in React Server Components using the `error.tsx` convention. When a page throws an error, you can create an `error.tsx` file in the same or a parent directory to display a custom error message instead of the default error output.
2+
3+
The example includes a page component that intentionally throws an error within an `ErrorComponent`. Since the error is not caught within the component, the custom error message defined in `error.tsx` is rendered instead. The `error.tsx` file must be a client component because error handling occurs on the client side.
4+
5+
The provided code snippets illustrate the setup: the main page component includes an error-throwing component, while the `error.tsx` file defines a user-friendly error message. This approach enhances user experience by providing clearer feedback when errors occur, although it affects the entire app. The document also suggests that using explicit error boundaries can be a more refined way to manage errors, allowing other content on the page to remain visible.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This example demonstrates the behavior of a React page when an error is thrown in a component without an error boundary to catch it. The `NoHandling` component includes an `ErrorComponent` that intentionally throws an error. When this occurs, the error propagates up to the nearest error boundary, which in this case is the root of the application. The output differs between development and production modes, affecting the overall user experience negatively. The example suggests improving error handling by implementing either an explicit error boundary or using a dedicated error handling component.

read-next/summaries/errors/reset

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
This example demonstrates how to implement error handling and retry functionality in React Server Components using an error boundary. The main component, `ResettablePage`, includes a child component, `ErrorComponent`, which randomly throws an error 50% of the time. When an error occurs, a fallback UI defined in `error.tsx` is displayed, featuring a "Retry" button that allows users to reset the page without refreshing the browser.
2+
3+
The `ErrorComponent` simulates a delay before potentially throwing an error, while the `ErrorMessage` component manages the retry logic. It uses the `useRouter` hook from Next.js to refresh the page when the "Retry" button is clicked. A spinner is shown during the reset process to enhance user experience.
4+
5+
Key points include:
6+
- The `reset()` function provided by Next.js only resets the state of the error boundary, not the page itself.
7+
- The `router.refresh()` method is called to re-render the entire page, which is wrapped in a `startTransition` to prevent UI flickering.
8+
- The example emphasizes the importance of providing users with a way to recover from errors gracefully.
9+
10+
For more advanced error handling, the document suggests implementing retry functionality at the component level instead of the page level.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This example demonstrates how to handle errors in React Server Components using an `ErrorBoundary`. The main component, `ResettablePage`, includes a child component, `ErrorComponent`, which has a 50% chance of throwing an error. If an error occurs, the `ErrorBoundary` catches it and displays an `ErrorFallback` component, which includes a Reset button.
2+
3+
The `ErrorComponent` simulates a delay before potentially throwing an error, and if it succeeds, it renders a message. The `ErrorFallback` component provides a user-friendly way to retry loading the component by calling a `retry` function that refreshes the page using `router.refresh()`. This function is wrapped in a `startTransition` to prevent UI flickering during the refresh process.
4+
5+
The example emphasizes that while the `resetErrorBoundary` function resets the error state, it does not refresh the page; instead, `router.refresh()` is necessary for that. This approach allows users to recover from errors without needing to refresh the entire page, enhancing the user experience.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This example demonstrates the use of React Server Components without employing `<Suspense>` boundaries or a `loading.tsx` file. It illustrates a scenario where data is fetched from a simulated fast database, which returns results in approximately 20 milliseconds. The code defines an asynchronous function, `slowDataLoad`, that mimics a database call and resolves after a short delay. The main component, `Page`, awaits this data and renders it alongside a header and a note about the absence of `<Suspense>`. The key takeaway is that for quick data fetches, the lack of `<Suspense>` does not negatively impact performance, but developers should be cautious as slower fetches could lead to degraded user experience.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
This example demonstrates the use of React Server Components with `<Suspense>` boundaries to optimize UI rendering. It showcases how to render static content immediately while handling asynchronous data fetching in a non-blocking manner. The main component, `Page`, includes a `DataComponent` that simulates a 3-second data fetch. By wrapping `DataComponent` in a `<Suspense>` boundary, the static content is rendered right away, and a loading placeholder is displayed until the data is ready. Once the data is fetched, it is streamed to the browser as part of the same HTTP request. This approach allows for efficient rendering and improved user experience by minimizing wait times for the user.

0 commit comments

Comments
 (0)