{"id":22978226,"url":"https://github.com/jonathanhefner/next-remote-components","last_synced_at":"2025-11-11T20:25:53.366Z","repository":{"id":266729117,"uuid":"899179123","full_name":"jonathanhefner/next-remote-components","owner":"jonathanhefner","description":null,"archived":false,"fork":false,"pushed_at":"2025-03-31T17:03:43.000Z","size":204,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-31T18:23:26.950Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://next-remote-components.vercel.app","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonathanhefner.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-05T19:08:03.000Z","updated_at":"2025-03-31T17:03:49.000Z","dependencies_parsed_at":"2024-12-05T20:21:54.846Z","dependency_job_id":"72d0f2b8-74fe-46f4-982b-7322bbd283f4","html_url":"https://github.com/jonathanhefner/next-remote-components","commit_stats":null,"previous_names":["jonathanhefner/next-remote-components"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanhefner%2Fnext-remote-components","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanhefner%2Fnext-remote-components/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanhefner%2Fnext-remote-components/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonathanhefner%2Fnext-remote-components/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonathanhefner","download_url":"https://codeload.github.com/jonathanhefner/next-remote-components/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246779320,"owners_count":20832363,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-15T01:02:33.196Z","updated_at":"2025-11-11T20:25:48.346Z","avatar_url":"https://github.com/jonathanhefner.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# next-remote-components\n\nThis is a userland prototype and demo of remote components — React server components that are rendered remotely, on demand by client components, without the need for an explicit fetch or dedicated API endpoint.\n\nSee it in action at https://next-remote-components.vercel.app/.\n\nThe core implementation is in [`lib/rrc.tsx`](./lib/rrc.tsx).\n\nMy hope is that React itself will eventually implement this functionality.  In the mean time, this project serves as a proof of concept.\n\n\n## Usage\n\nTo use remote components in your own project, copy [`lib/rrc.tsx`](./lib/rrc.tsx) into your project, and then follow these steps:\n\n1. Create a server function that returns a component:\n\n    ```tsx\n    // @/lib/server-functions.tsx\n    'use server'\n\n    export async function getMyRemoteComponent() {\n      return \u003cstrong\u003eHello from the server!\u003c/strong\u003e\n    }\n    ```\n\n2. Define a remote component via the `remote()` helper:\n\n    ```tsx\n    // @/lib/client-components.tsx\n    'use client'\n\n    import { getMyRemoteComponent } from \"@/lib/server-functions\"\n    import { remote } from \"@/lib/rrc\"\n\n    const MyRemoteComponent = remote(getMyRemoteComponent)\n    ```\n\n\n3. Create a client component that uses the remote component wrapped in a `\u003cRemoteSuspense\u003e` boundary:\n\n    ```tsx\n    // @/lib/client-components.tsx\n    'use client'\n\n    import { getMyRemoteComponent } from \"@/lib/server-functions\"\n    import { remote, RemoteSuspense } from \"@/lib/rrc\"\n\n    const MyRemoteComponent = remote(getMyRemoteComponent)\n\n    export function MyClientComponent() {\n      return (\n        \u003cRemoteSuspense fallback=\"Loading...\"\u003e\n          \u003cp\u003eThe server says: \u003cMyRemoteComponent /\u003e\u003c/p\u003e\n        \u003c/RemoteSuspense\u003e\n      )\n    }\n    ```\n\n\n## Features\n\n### Static typing\n\nRemote components and their props are statically typed.  For example:\n\n  ```tsx\n  export async function getMyRemoteComponent(props: { value: number }) {\n    return \u003c\u003e\u003c/\u003e\n  }\n  ```\n\n  ```tsx\n  const MyRemoteComponent = remote(getMyRemoteComponent)\n\n  export function MyClientComponent() {\n    return (\n      \u003cRemoteSuspense fallback=\"Loading...\"\u003e\n        {/* ERROR: Property 'value' is missing in type '{}' but required in type '{ value: number; }' */}\n        \u003cMyRemoteComponent /\u003e\n\n        {/* ERROR: Type 'string' is not assignable to type 'number' */}\n        \u003cMyRemoteComponent value=\"100\" /\u003e\n\n        {/* ERROR: Type '{ children: string; value: number; }' is not assignable to type 'IntrinsicAttributes \u0026 { value: number; }' */}\n        \u003cMyRemoteComponent value={100}\u003echild\u003c/MyRemoteComponent\u003e\n\n        {/* CORRECT! */}\n        \u003cMyRemoteComponent value={100} /\u003e\n      \u003c/RemoteSuspense\u003e\n    )\n  }\n  ```\n\n### Client components as children\n\nRemote components support \"passing\" client components as children.  Behind the scenes, the remote components render a slot which is then filled with the given children.  For example:\n\n  ```tsx\n  export async function getMyRemoteComponent({ children }: { children: React.ReactNode }) {\n    return \u003c\u003e\n      I have twins:\n\n      \u003cul\u003e\n        \u003cli\u003e{children}\u003c/li\u003e\n        \u003cli\u003e{children}\u003c/li\u003e\n      \u003c/ul\u003e\n    \u003c/\u003e\n  }\n  ```\n\n  ```tsx\n  const MyRemoteComponent = remote(getMyRemoteComponent)\n\n  export function MyClientComponent() {\n    return (\n      \u003cRemoteSuspense fallback=\"Loading...\"\u003e\n        \u003cMyRemoteComponent\u003echild\u003c/MyRemoteComponent\u003e\n      \u003c/RemoteSuspense\u003e\n    )\n  }\n  ```\n\n\n## Caveats\n\n### Props must be serializable\n\nRemote components props are serialized in the same way as server function arguments.  Thus, props values must be one of the [supported types](https://19.react.dev/reference/rsc/use-server#serializable-parameters-and-return-values).\n\n### Memoization and rerenders\n\nRemote components are memoized using React's [`memo`](https://19.react.dev/reference/react/memo), with special casing when passing children.  Thus, a remote component will rerender when a prop value changes according to [`Object.is`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is).\n\nIn the future, the `remote()` helper might accept additional arguments to customize this behavior.\n\n\n## Further improvements from a non-userland implementation\n\n### DX improvements\n\nThe behavior of `\u003cRemoteSuspense\u003e` could be folded into React's built-in `\u003cSuspense\u003e` boundary.  Thus, developers could simply use `\u003cSuspense\u003e` as they would elsewhere.\n\n### Performance improvements\n\nRemote components rely on server functions which, currently, are [not recommended for data fetching](https://19.react.dev/reference/rsc/use-server#caveats) because they run sequentially and are not cacheable.  However, in the future, there may be variant of server functions which _are_ designed for data fetching.  One proposal is to special case server functions based on naming convention, such that functions that start with `get...` (e.g. `getData()`) are treated as data fetching functions.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonathanhefner%2Fnext-remote-components","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonathanhefner%2Fnext-remote-components","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonathanhefner%2Fnext-remote-components/lists"}