Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 0 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: PR

on:
pull_request:
push:
branches: ['svelte-5-adapter']

concurrency:
group: ${{ github.workflow }}-${{ github.event.number || github.ref }}
Expand Down
2 changes: 1 addition & 1 deletion examples/react/rick-morty/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />

<title>TanStack Query React Rick And Morty Example App</title>
<title>TanStack Query React Rick And Morty Example</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
6 changes: 2 additions & 4 deletions examples/react/rick-morty/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@
"preview": "vite preview"
},
"dependencies": {
"@emotion/react": "^11.13.5",
"@emotion/styled": "^11.13.5",
"@mui/material": "^6.1.8",
"@mui/styles": "^6.1.8",
"@tanstack/react-query": "^5.90.2",
"@tanstack/react-query-devtools": "^5.90.2",
"react": "^19.0.0",
Expand All @@ -20,7 +16,9 @@
"react-router-dom": "^6.25.1"
},
"devDependencies": {
"@tailwindcss/vite": "^4.1.13",
"@vitejs/plugin-react": "^4.3.4",
"tailwindcss": "^4.1.13",
"typescript": "5.8.3",
"vite": "^6.3.6"
}
Expand Down
31 changes: 2 additions & 29 deletions examples/react/rick-morty/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { BrowserRouter as Router } from 'react-router-dom'
import { ThemeProvider } from '@mui/material'
import { createTheme } from '@mui/material/styles'
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import Layout from './Layout'
Expand All @@ -13,34 +11,9 @@ export default function App() {
return (
<QueryClientProvider client={queryClient}>
<Router>
<ThemeProvider theme={theme}>
<Layout />
<ReactQueryDevtools initialIsOpen />
</ThemeProvider>
<Layout />
<ReactQueryDevtools initialIsOpen />
</Router>
</QueryClientProvider>
)
}

const theme = createTheme({
typography: {
h1: {
fontFamily: 'Roboto Mono, monospace',
},
h2: {
fontFamily: 'Roboto Mono, monospace',
},
h3: {
fontFamily: 'Roboto Mono, monospace',
},
h4: {
fontFamily: 'Roboto Mono, monospace',
},
h5: {
fontFamily: 'Roboto Mono, monospace',
},
h6: {
fontFamily: 'Roboto Mono, monospace',
},
},
})
117 changes: 0 additions & 117 deletions examples/react/rick-morty/src/Character.jsx

This file was deleted.

87 changes: 87 additions & 0 deletions examples/react/rick-morty/src/Character.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import { useParams, Link as RouterLink } from 'react-router-dom'
import { useQuery } from '@tanstack/react-query'
import { getCharacter, getEpisode, getLocation } from './api'

function Character() {
let params = useParams()
const characterId = params.characterId!

const { status, data } = useQuery({
queryKey: ['character', characterId],
queryFn: () => getCharacter(characterId),
})

if (status === 'pending') return <p>Loading...</p>
if (status === 'error') return <p>Error :(</p>

const locationUrlParts = data.location.url.split('/').filter(Boolean)
const locationId = locationUrlParts[locationUrlParts.length - 1]

return (
<div>
<h2 className="text-4xl">{data.name}</h2>
<p>
<strong>Gender</strong>: {data.gender}
</p>
<p>
<strong>Status</strong>: {data.status}
</p>
<p>
<strong>Species</strong>: {data.species}
</p>
<p>
<strong>Origin</strong>: {data.origin.name}
</p>
<p>
<strong>Location</strong>: <Location locationId={locationId} />
</p>
Comment on lines +17 to +37
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Handle empty location URLs before deriving the location ID.

Line 17 assumes data.location.url is always populated. For characters whose location URL is an empty string (common in this API), locationId becomes undefined, and the Location component calls getLocation(undefined), repeatedly 404ing and rendering Error :( instead of the known location name. Guard for a missing URL and fall back to the provided name.

-  const locationUrlParts = data.location.url.split('/').filter(Boolean)
-  const locationId = locationUrlParts[locationUrlParts.length - 1]
+  const locationUrl = data.location.url
+  const locationId = locationUrl
+    ? locationUrl.split('/').filter(Boolean).slice(-1)[0]
+    : undefined-        <strong>Location</strong>: <Location locationId={locationId} />
+        <strong>Location</strong>:{' '}
+        {locationId ? (
+          <Location locationId={locationId} />
+        ) : (
+          data.location.name
+        )}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
const locationUrlParts = data.location.url.split('/').filter(Boolean)
const locationId = locationUrlParts[locationUrlParts.length - 1]
return (
<div>
<h2 className="text-4xl">{data.name}</h2>
<p>
<strong>Gender</strong>: {data.gender}
</p>
<p>
<strong>Status</strong>: {data.status}
</p>
<p>
<strong>Species</strong>: {data.species}
</p>
<p>
<strong>Origin</strong>: {data.origin.name}
</p>
<p>
<strong>Location</strong>: <Location locationId={locationId} />
</p>
// Handle empty location URLs before deriving the location ID
const locationUrl = data.location.url
const locationId = locationUrl
? locationUrl.split('/').filter(Boolean).slice(-1)[0]
: undefined
return (
<div>
<h2 className="text-4xl">{data.name}</h2>
<p>
<strong>Gender</strong>: {data.gender}
</p>
<p>
<strong>Status</strong>: {data.status}
</p>
<p>
<strong>Species</strong>: {data.species}
</p>
<p>
<strong>Origin</strong>: {data.origin.name}
</p>
<p>
<strong>Location</strong>:{' '}
{locationId ? (
<Location locationId={locationId} />
) : (
data.location.name
)}
</p>
</div>
)
🤖 Prompt for AI Agents
In examples/react/rick-morty/src/Character.tsx around lines 17 to 37, the code
assumes data.location.url is always populated which leads to locationId becoming
undefined for empty URLs; change the logic to only derive locationId when
data.location.url is a non-empty string (e.g., check truthiness before
splitting) and then conditionally render <Location locationId={locationId} />
only if locationId exists; otherwise render the provided fallback name
(data.location.name) so we don't call getLocation(undefined) and show "Error :("
repeatedly.


<h4 className="text-2xl pt-4">Episodes</h4>
{data.episode.map((episode: any) => {
const episodeUrlParts = episode.split('/').filter(Boolean)
const episodeId = episodeUrlParts[episodeUrlParts.length - 1]
return <Episode episodeId={episodeId} key={`${episodeId}`} />
})}
</div>
)
}

function Episode({ episodeId }: { episodeId: string }) {
const { data, status } = useQuery({
queryKey: ['episode', episodeId],
queryFn: () => getEpisode(episodeId),
})

if (status === 'success') {
return (
<article key={episodeId}>
<RouterLink
className="text-blue-500 hover:underline"
to={`/episodes/${episodeId}`}
>
<h6 className="text-lg">
{data.episode}. {data.name} - {data.air_date}
</h6>
</RouterLink>
</article>
)
}
}

function Location({ locationId }: { locationId: string }) {
const { data, status } = useQuery({
queryKey: ['location', locationId],
queryFn: () => getLocation(locationId),
})

if (status === 'pending') return <span>Loading...</span>
if (status === 'error') return <span>Error :(</span>

return (
<span>
{data.name} - {data.type}
</span>
)
}

export default Character
34 changes: 0 additions & 34 deletions examples/react/rick-morty/src/Characters.jsx

This file was deleted.

33 changes: 33 additions & 0 deletions examples/react/rick-morty/src/Characters.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { Link as RouterLink } from 'react-router-dom'
import { useQuery } from '@tanstack/react-query'
import { getCharacters } from './api'

export default function Characters() {
const { status, data } = useQuery({
queryKey: ['characters'],
queryFn: () => getCharacters(),
})

if (status === 'pending') return <p>Loading...</p>
if (status === 'error') return <p>Error :(</p>

return (
<div>
<h2 className="text-4xl">Characters</h2>
{data.results.map((person: any) => {
return (
<article key={person.id}>
<RouterLink
className="text-blue-500 hover:underline"
to={`/characters/${person.id}`}
>
<h6 className="text-xl">
{person.name} - {person.gender}: {person.species}
</h6>
</RouterLink>
</article>
)
})}
</div>
)
}
Loading