From 20427036c9803a9a47da91ef3443c6024497b677 Mon Sep 17 00:00:00 2001 From: Alex Godfrey <42598293+alexjamesgodfrey@users.noreply.github.com> Date: Thu, 25 Sep 2025 12:27:53 -0700 Subject: [PATCH 1/4] Update environment-functions.md with correct function names --- .../framework/react/environment-functions.md | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/docs/start/framework/react/environment-functions.md b/docs/start/framework/react/environment-functions.md index 6e0a5196ee2..0711f602b60 100644 --- a/docs/start/framework/react/environment-functions.md +++ b/docs/start/framework/react/environment-functions.md @@ -1,17 +1,18 @@ ---- +di--- id: environment-functions title: Environment Functions + --- ## What Are Environment Functions? Environment functions are utilities designed to define and control function execution based on the runtime environment—whether the code is running on the client or the server. These utilities help ensure that environment-specific logic is executed safely and intentionally, preventing runtime errors and improving maintainability in fullstack or isomorphic applications. -Start provide three core environment functions: +Start provides three core environment functions: - `createIsomorphicFn`: Compose a single function that adapts to both client and server environments. -- `serverOnly`: Ensures a function can only run on the server. -- `clientOnly`: Ensures a function can only run on the client. +- `createServerOnlyFn`: Create a function that can only run on the server. +- `createClientOnlyFn`: Create a function that can only run on the client. --- @@ -87,28 +88,28 @@ function noop() {} ## `env`Only Functions -The `serverOnly` and `clientOnly` helpers enforce strict environment-bound execution. They ensure the decorated function is only callable in the correct runtime context. If misused, they throw descriptive runtime errors to prevent unintentional logic execution. +The `createServerOnlyFn` and `createClientOnlyFn` helpers enforce strict environment-bound execution. They ensure the returned function is only callable in the correct runtime context. If misused, they throw descriptive runtime errors to prevent unintentional logic execution. -### `serverOnly` +### `createServerOnlyFn` ```tsx -import { serverOnly } from '@tanstack/react-start' +import { createServerOnlyFn } from '@tanstack/react-start' -const foo = serverOnly(() => 'bar') +const foo = createServerOnlyFn(() => 'bar') foo() // ✅ On server: returns "bar" -// ❌ On client: throws "serverOnly() functions can only be called on the server!" +// ❌ On client: throws "createServerOnlyFn() functions can only be called on the server!" ``` -### `clientOnly` +### `createClientOnlyFn` ```tsx -import { clientOnly } from '@tanstack/react-start' +import { createClientOnlyFn } from '@tanstack/react-start' -const foo = clientOnly(() => 'bar') +const foo = createClientOnlyFn(() => 'bar') foo() // ✅ On client: returns "bar" -// ❌ On server: throws "clientOnly() functions can only be called on the client!" +// ❌ On server: throws "createClientOnlyFn() functions can only be called on the client!" ``` > [!NOTE] @@ -120,4 +121,4 @@ Environment functions are tree-shaken based on the environment for each bundle p Functions created using `createIsomorphicFn()` are tree-shaken. All codes inside `.client()` are not included in server bundle, and vice-versa. -On the server, implementation of `clientOnly` functions are replaced with a function that throws an `Error`. The reverse is true for `serverOnly` functions on the client. +On the server, functions created using `createClientOnlyFn()` functions are replaced with a function that throws an `Error` on the server. The reverse is true for `createServerOnlyFn` functions on the client. From f42027d52a4bf0e2d7b60aa66bc68a9e8e048ded Mon Sep 17 00:00:00 2001 From: Alex Godfrey <42598293+alexjamesgodfrey@users.noreply.github.com> Date: Thu, 25 Sep 2025 12:57:17 -0700 Subject: [PATCH 2/4] Update environment-functions.md --- docs/start/framework/react/environment-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/start/framework/react/environment-functions.md b/docs/start/framework/react/environment-functions.md index 0711f602b60..9f73c80dac2 100644 --- a/docs/start/framework/react/environment-functions.md +++ b/docs/start/framework/react/environment-functions.md @@ -1,4 +1,4 @@ -di--- +--- id: environment-functions title: Environment Functions From cc27565ec5cca4020340a6e1cac5d9751b9ccf83 Mon Sep 17 00:00:00 2001 From: Alex Godfrey <42598293+alexjamesgodfrey@users.noreply.github.com> Date: Thu, 25 Sep 2025 12:57:59 -0700 Subject: [PATCH 3/4] Update environment-functions.md --- docs/start/framework/react/environment-functions.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/start/framework/react/environment-functions.md b/docs/start/framework/react/environment-functions.md index 9f73c80dac2..f1e854085e0 100644 --- a/docs/start/framework/react/environment-functions.md +++ b/docs/start/framework/react/environment-functions.md @@ -1,7 +1,6 @@ --- id: environment-functions title: Environment Functions - --- ## What Are Environment Functions? From f93f8729f2b373b36d6d11b769bd90192d012a27 Mon Sep 17 00:00:00 2001 From: Nico Lynzaad <44094871+nlynzaad@users.noreply.github.com> Date: Fri, 26 Sep 2025 00:26:55 +0200 Subject: [PATCH 4/4] remove doubles reference to "functions" --- docs/start/framework/react/environment-functions.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/start/framework/react/environment-functions.md b/docs/start/framework/react/environment-functions.md index f1e854085e0..f472a3a26a3 100644 --- a/docs/start/framework/react/environment-functions.md +++ b/docs/start/framework/react/environment-functions.md @@ -120,4 +120,4 @@ Environment functions are tree-shaken based on the environment for each bundle p Functions created using `createIsomorphicFn()` are tree-shaken. All codes inside `.client()` are not included in server bundle, and vice-versa. -On the server, functions created using `createClientOnlyFn()` functions are replaced with a function that throws an `Error` on the server. The reverse is true for `createServerOnlyFn` functions on the client. +On the server, functions created using `createClientOnlyFn()` are replaced with a function that throws an `Error` on the server. The reverse is true for `createServerOnlyFn` functions on the client.