Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/start/framework/react/guide/code-execution-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ export const Route = createFileRoute('/users')({
loader: () => {
// This runs on BOTH server and client!
const secret = process.env.SECRET // Exposed to client
return fetch(`/api/users?key=${secret}`)
return fetch(`https://api.example.com/api/users?key=${secret}`)
},
})

// ✅ Use server function for server-only operations
const getUsersSecurely = createServerFn().handler(() => {
const secret = process.env.SECRET // Server-only
return fetch(`/api/users?key=${secret}`)
return fetch(`https://api.example.com/api/users?key=${secret}`)
})

export const Route = createFileRoute('/users')({
Expand Down
6 changes: 3 additions & 3 deletions docs/start/framework/react/guide/execution-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function formatPrice(price: number) {
export const Route = createFileRoute('/products')({
loader: async () => {
// This runs on server during SSR AND on client during navigation
const response = await fetch('/api/products')
const response = await fetch('https://api.example.com/api/products')
return response.json()
},
})
Expand Down Expand Up @@ -223,14 +223,14 @@ export const Route = createFileRoute('/users')({
loader: () => {
// This runs on BOTH server and client!
const secret = process.env.SECRET // Exposed to client
return fetch(`/api/users?key=${secret}`)
return fetch(`https://api.example.com/api/users?key=${secret}`)
},
})

// ✅ Use server function for server-only operations
const getUsersSecurely = createServerFn().handler(() => {
const secret = process.env.SECRET // Server-only
return fetch(`/api/users?key=${secret}`)
return fetch(`https://api.example.com/api/users?key=${secret}`)
})

export const Route = createFileRoute('/users')({
Expand Down
4 changes: 2 additions & 2 deletions docs/start/framework/solid/guide/code-execution-patterns.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,14 @@ export const Route = createFileRoute('/users')({
loader: () => {
// This runs on BOTH server and client!
const secret = process.env.SECRET // Exposed to client
return fetch(`/api/users?key=${secret}`)
return fetch(`https://api.example.com/api/users?key=${secret}`)
},
})

// ✅ Use server function for server-only operations
const getUsersSecurely = createServerFn().handler(() => {
const secret = process.env.SECRET // Server-only
return fetch(`/api/users?key=${secret}`)
return fetch(`https://api.example.com/api/users?key=${secret}`)
})

export const Route = createFileRoute('/users')({
Expand Down
6 changes: 3 additions & 3 deletions docs/start/framework/solid/guide/execution-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function formatPrice(price: number) {
export const Route = createFileRoute('/products')({
loader: async () => {
// This runs on server during SSR AND on client during navigation
const response = await fetch('/api/products')
const response = await fetch('https://api.example.com/api/products')
return response.json()
},
})
Expand Down Expand Up @@ -211,14 +211,14 @@ export const Route = createFileRoute('/users')({
loader: () => {
// This runs on BOTH server and client!
const secret = process.env.SECRET // Exposed to client
return fetch(`/api/users?key=${secret}`)
return fetch(`https://api.example.com/api/users?key=${secret}`)
},
})

// ✅ Use server function for server-only operations
const getUsersSecurely = createServerFn().handler(() => {
const secret = process.env.SECRET // Server-only
return fetch(`/api/users?key=${secret}`)
return fetch(`https://api.example.com/api/users?key=${secret}`)
})

export const Route = createFileRoute('/users')({
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { createFileRoute } from '@tanstack/react-router'
import { getRouterInstance } from '@tanstack/react-start'
import { NotFound } from '../components/NotFound'
import { UserErrorComponent } from '../components/UserError'
import type { User } from '~/utils/users'

export const Route = createFileRoute('/users/$userId')({
loader: async ({ params: { userId } }) => {
try {
const res = await fetch('/api/users/' + userId)
const router = await getRouterInstance()
const res = await fetch(new URL('/api/users/' + userId, router.origin))
if (!res.ok) {
throw new Error('Unexpected status code')
}
Expand Down
4 changes: 3 additions & 1 deletion examples/react/start-basic-cloudflare/src/routes/users.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Link, Outlet, createFileRoute } from '@tanstack/react-router'
import { getRouterInstance } from '@tanstack/react-start'
import type { User } from '~/utils/users'

export const Route = createFileRoute('/users')({
loader: async () => {
const res = await fetch('/api/users')
const router = await getRouterInstance()
const res = await fetch(new URL('/api/users', router.origin))

if (!res.ok) {
throw new Error('Unexpected status code')
Expand Down
4 changes: 3 additions & 1 deletion examples/react/start-basic/src/routes/users.$userId.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { createFileRoute } from '@tanstack/react-router'
import { getRouterInstance } from '@tanstack/react-start'
import { NotFound } from '../components/NotFound'
import { UserErrorComponent } from '../components/UserError'
import type { User } from '../utils/users'

export const Route = createFileRoute('/users/$userId')({
loader: async ({ params: { userId } }) => {
try {
const res = await fetch('/api/users/' + userId)
const router = await getRouterInstance()
const res = await fetch(new URL('/api/users/' + userId, router.origin))
if (!res.ok) {
throw new Error('Unexpected status code')
}
Expand Down
4 changes: 3 additions & 1 deletion examples/react/start-basic/src/routes/users.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Link, Outlet, createFileRoute } from '@tanstack/react-router'
import { getRouterInstance } from '@tanstack/react-start'
import type { User } from '../utils/users'

export const Route = createFileRoute('/users')({
loader: async () => {
const res = await fetch('/api/users')
const router = await getRouterInstance()
const res = await fetch(new URL('/api/users', router.origin))
Comment on lines +7 to +8

if (!res.ok) {
throw new Error('Unexpected status code')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { createFileRoute } from '@tanstack/solid-router'
import { getRouterInstance } from '@tanstack/solid-start'
import { NotFound } from '../components/NotFound'
import { UserErrorComponent } from '../components/UserError'
import type { User } from '../utils/users'

export const Route = createFileRoute('/users/$userId')({
loader: async ({ params: { userId } }) => {
try {
const res = await fetch('/api/users/' + userId)
const router = await getRouterInstance()
const res = await fetch(new URL('/api/users/' + userId, router.origin))
if (!res.ok) {
throw new Error('Unexpected status code')
}
Expand Down
4 changes: 3 additions & 1 deletion examples/solid/start-basic-cloudflare/src/routes/users.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Link, Outlet, createFileRoute } from '@tanstack/solid-router'
import { getRouterInstance } from '@tanstack/solid-start'
import type { User } from '../utils/users'

export const Route = createFileRoute('/users')({
loader: async () => {
const res = await fetch('/api/users')
const router = await getRouterInstance()
const res = await fetch(new URL('/api/users', router.origin))

if (!res.ok) {
throw new Error('Unexpected status code')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { createFileRoute } from '@tanstack/solid-router'
import { getRouterInstance } from '@tanstack/solid-start'
import { NotFound } from '../components/NotFound'
import { UserErrorComponent } from '../components/UserError'
import type { User } from '../utils/users'

export const Route = createFileRoute('/users/$userId')({
loader: async ({ params: { userId } }) => {
try {
const res = await fetch('/api/users/' + userId)
const router = await getRouterInstance()
const res = await fetch(new URL('/api/users/' + userId, router.origin))
if (!res.ok) {
throw new Error('Unexpected status code')
}
Expand Down
4 changes: 3 additions & 1 deletion examples/solid/start-basic-netlify/src/routes/users.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Link, Outlet, createFileRoute } from '@tanstack/solid-router'
import { getRouterInstance } from '@tanstack/solid-start'
import type { User } from '../utils/users'

export const Route = createFileRoute('/users')({
loader: async () => {
const res = await fetch('/api/users')
const router = await getRouterInstance()
const res = await fetch(new URL('/api/users', router.origin))

if (!res.ok) {
throw new Error('Unexpected status code')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { createFileRoute } from '@tanstack/solid-router'
import { getRouterInstance } from '@tanstack/solid-start'
import { NotFound } from '../components/NotFound'
import { UserErrorComponent } from '../components/UserError'
import type { User } from '../utils/users'

export const Route = createFileRoute('/users/$userId')({
loader: async ({ params: { userId } }) => {
try {
const res = await fetch('/api/users/' + userId)
const router = await getRouterInstance()
const res = await fetch(new URL('/api/users/' + userId, router.origin))
if (!res.ok) {
throw new Error('Unexpected status code')
}
Expand Down
4 changes: 3 additions & 1 deletion examples/solid/start-basic-nitro/src/routes/users.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Link, Outlet, createFileRoute } from '@tanstack/solid-router'
import { getRouterInstance } from '@tanstack/solid-start'
import type { User } from '../utils/users'

export const Route = createFileRoute('/users')({
loader: async () => {
const res = await fetch('/api/users')
const router = await getRouterInstance()
const res = await fetch(new URL('/api/users', router.origin))

if (!res.ok) {
throw new Error('Unexpected status code')
Expand Down
4 changes: 3 additions & 1 deletion examples/solid/start-basic/src/routes/users.$userId.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { createFileRoute } from '@tanstack/solid-router'
import { getRouterInstance } from '@tanstack/solid-start'
import { NotFound } from '../components/NotFound'
import { UserErrorComponent } from '../components/UserError'

export const Route = createFileRoute('/users/$userId')({
loader: async ({ params: { userId } }) => {
try {
const res = await fetch('/api/users/' + userId)
const router = await getRouterInstance()
const res = await fetch(new URL('/api/users/' + userId, router.origin))
Comment on lines +9 to +10
if (!res.ok) {
throw new Error('Unexpected status code')
}
Expand Down
4 changes: 3 additions & 1 deletion examples/solid/start-basic/src/routes/users.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Link, Outlet, createFileRoute } from '@tanstack/solid-router'
import { getRouterInstance } from '@tanstack/solid-start'
import type { User } from '../utils/users'

export const Route = createFileRoute('/users')({
loader: async () => {
const res = await fetch('/api/users')
const router = await getRouterInstance()
const res = await fetch(new URL('/api/users', router.origin))

if (!res.ok) {
throw new Error('Unexpected status code')
Expand Down