Skip to content

docs(start): createIsomorphicFn and envOnly #4806

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hokkyss
Copy link

@hokkyss hokkyss commented Jul 28, 2025

Add docs for createIsomorphicFn, serverOnly, and clientOnly.

I am not quite sure whether "environment functions" is a good name though

@github-actions github-actions bot added the documentation Everything documentation related label Jul 28, 2025
@hokkyss hokkyss changed the title docs(start): environment functions docs docs(start): createIsomorphicFn and envOnly Jul 28, 2025
@hokkyss hokkyss force-pushed the main branch 2 times, most recently from c503c69 to a675dae Compare July 29, 2025 01:18
### Complete Implementation

```tsx
const getEnv = createIsomorphicFn()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make those snippets complete by adding the import from '@tanstack/solid-start'

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applies to all examples

@@ -0,0 +1,3 @@
---
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

once we have settled on the text for react, please duplicate and change the imports to point to solid

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hokkyss see the docs in docs/router/framework/solid/devtools.md which have a syntax for performing text replacements on the ref doc. So you shouldn't need to duplicate the entire document.

@@ -98,7 +98,7 @@ response?: 'data' | 'full' | 'raw'
- From other server functions

> [!WARNING]
> Server functions cannot be called from API Routes. If you need to share business logic between server functions and API Routes, extract the shared logic into utility functions that can be imported by both.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think we can now call server functions from API routes. please check and and if true, this text can be removed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schiller-manuel is right. API routes as a whole became the new "Server Routes" which support calling Server Function.

This warning can be removed.

@schiller-manuel
Copy link
Contributor

we also got those docs recently: b402bbc

maybe just improve those where needed?

@@ -98,7 +98,7 @@ response?: 'data' | 'full' | 'raw'
- From other server functions

> [!WARNING]
> Server functions cannot be called from API Routes. If you need to share business logic between server functions and API Routes, extract the shared logic into utility functions that can be imported by both.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@schiller-manuel is right. API routes as a whole became the new "Server Routes" which support calling Server Function.

This warning can be removed.

@@ -0,0 +1,3 @@
---
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hokkyss see the docs in docs/router/framework/solid/devtools.md which have a syntax for performing text replacements on the ref doc. So you shouldn't need to duplicate the entire document.

Use `createIsomorphicFn()` to define functions that behave differently depending on whether they are called on the client or the server. This is useful for safely sharing logic across environments while delegating environment-specific behavior to appropriate handlers.

> [!WARNING]
> Unimplemented function results in a no-op function.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe instead of a warning, this could be a small heading like "What is a no-op?", that'd show the user the type of a no-op.

Perhaps something like this:

type NoOpFunction = () => undefined // add a comment here

@@ -122,6 +126,10 @@
"label": "Static Server Functions",
"to": "framework/solid/static-server-functions"
},
{
"label": "Environment Functions",
"to": "framework/react/environment-functions"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"to": "framework/react/environment-functions"
"to": "framework/solid/environment-functions"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Everything documentation related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants