-
-
Notifications
You must be signed in to change notification settings - Fork 209
Migrate Apollo Client to v4 #2178
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
base: main
Are you sure you want to change the base?
Changes from all commits
839f515
5e68e09
6b2e8a4
b175fb9
9215da4
b8a110c
13c6f52
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
@@ -1,23 +1,27 @@ | ||||||||||
'use client' | ||||||||||
import { useQuery } from '@apollo/client' | ||||||||||
import { useQuery } from '@apollo/client/react' | ||||||||||
import Link from 'next/link' | ||||||||||
import { useParams } from 'next/navigation' | ||||||||||
import { useState, useEffect } from 'react' | ||||||||||
import { handleAppError, ErrorDisplay } from 'app/global-error' | ||||||||||
import { GET_CHAPTER_DATA } from 'server/queries/chapterQueries' | ||||||||||
import type { Chapter } from 'types/chapter' | ||||||||||
import { | ||||||||||
GetChapterDataDocument, | ||||||||||
GetChapterDataQuery, | ||||||||||
} from 'types/__generated__/chapterQueries.generated' | ||||||||||
import type { Contributor } from 'types/contributor' | ||||||||||
import { formatDate } from 'utils/dateFormatter' | ||||||||||
import DetailsCard from 'components/CardDetailsPage' | ||||||||||
import LoadingSpinner from 'components/LoadingSpinner' | ||||||||||
|
||||||||||
export default function ChapterDetailsPage() { | ||||||||||
const { chapterKey } = useParams() | ||||||||||
const [chapter, setChapter] = useState<Chapter>({} as Chapter) | ||||||||||
const { chapterKey } = useParams<{ chapterKey: string }>() | ||||||||||
const [chapter, setChapter] = useState<GetChapterDataQuery['chapter']>( | ||||||||||
{} as GetChapterDataQuery['chapter'] | ||||||||||
) | ||||||||||
Comment on lines
+18
to
+20
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Avoid using type assertion for initial state. Using - const [chapter, setChapter] = useState<GetChapterDataQuery['chapter']>(
- {} as GetChapterDataQuery['chapter']
- )
+ const [chapter, setChapter] = useState<GetChapterDataQuery['chapter']>(null) This change requires the state to explicitly handle 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
||||||||||
const [topContributors, setTopContributors] = useState<Contributor[]>([]) | ||||||||||
const [isLoading, setIsLoading] = useState<boolean>(true) | ||||||||||
|
||||||||||
const { data, error: graphQLRequestError } = useQuery(GET_CHAPTER_DATA, { | ||||||||||
const { data, error: graphQLRequestError } = useQuery(GetChapterDataDocument, { | ||||||||||
variables: { key: chapterKey }, | ||||||||||
}) | ||||||||||
|
||||||||||
|
@@ -63,7 +67,7 @@ export default function ChapterDetailsPage() { | |||||||||
<DetailsCard | ||||||||||
details={details} | ||||||||||
entityKey={chapter.key} | ||||||||||
geolocationData={[chapter]} | ||||||||||
geolocationData={[chapter]} // TODO: change the type of component | ||||||||||
isActive={chapter.isActive} | ||||||||||
socialLinks={chapter.relatedUrls} | ||||||||||
summary={chapter.summary} | ||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
'use client' | ||
import { useQuery } from '@apollo/client' | ||
import { useQuery } from '@apollo/client/react' | ||
import { | ||
faCodeMerge, | ||
faFolderOpen, | ||
|
@@ -12,26 +12,22 @@ import { useParams } from 'next/navigation' | |
import { useTheme } from 'next-themes' | ||
import React, { useState, useEffect, useRef } from 'react' | ||
import { handleAppError, ErrorDisplay } from 'app/global-error' | ||
import { GET_USER_DATA } from 'server/queries/userQueries' | ||
import type { Issue } from 'types/issue' | ||
import type { Milestone } from 'types/milestone' | ||
import type { RepositoryCardProps } from 'types/project' | ||
import type { PullRequest } from 'types/pullRequest' | ||
import type { Release } from 'types/release' | ||
import type { UserDetails } from 'types/user' | ||
import { GetUserDataDocument, GetUserDataQuery } from 'types/__generated__/userQueries.generated' | ||
import { formatDate } from 'utils/dateFormatter' | ||
import { drawContributions, fetchHeatmapData, HeatmapData } from 'utils/helpers/githubHeatmap' | ||
import DetailsCard from 'components/CardDetailsPage' | ||
import LoadingSpinner from 'components/LoadingSpinner' | ||
|
||
const UserDetailsPage: React.FC = () => { | ||
const { memberKey } = useParams() | ||
const [user, setUser] = useState<UserDetails | null>() | ||
const [issues, setIssues] = useState<Issue[]>([]) | ||
const [topRepositories, setTopRepositories] = useState<RepositoryCardProps[]>([]) | ||
const [milestones, setMilestones] = useState<Milestone[]>([]) | ||
const [pullRequests, setPullRequests] = useState<PullRequest[]>([]) | ||
const [releases, setReleases] = useState<Release[]>([]) | ||
const { memberKey } = useParams<{ memberKey: string }>() | ||
const [user, setUser] = useState<GetUserDataQuery['user'] | null>() | ||
const [issues, setIssues] = useState<GetUserDataQuery['recentIssues']>([]) | ||
const [topRepositories, setTopRepositories] = useState< | ||
GetUserDataQuery['topContributedRepositories'] | ||
>([]) | ||
const [milestones, setMilestones] = useState<GetUserDataQuery['recentMilestones']>([]) | ||
const [pullRequests, setPullRequests] = useState<GetUserDataQuery['recentPullRequests']>([]) | ||
const [releases, setReleases] = useState<GetUserDataQuery['recentReleases']>([]) | ||
const [data, setData] = useState<HeatmapData>({} as HeatmapData) | ||
const [isLoading, setIsLoading] = useState<boolean>(true) | ||
const [username, setUsername] = useState('') | ||
|
@@ -40,7 +36,7 @@ const UserDetailsPage: React.FC = () => { | |
const canvasRef = useRef<HTMLCanvasElement | null>(null) | ||
const theme = 'blue' | ||
Comment on lines
36
to
37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Heatmap never draws when data arrives; dead canvasRef and stale effect. Top-level canvasRef isn’t attached to any element; the draw effect depends on it and never runs. The inner Heatmap effect doesn’t react to data/username updates. Apply this diff to remove dead code and fix dependencies: - const canvasRef = useRef<HTMLCanvasElement | null>(null)
- const theme = 'blue'
@@
- useEffect(() => {
- if (canvasRef.current && data && data.years && data.years.length > 0) {
- drawContributions(canvasRef.current, { data, username, theme })
- const imageURL = canvasRef.current.toDataURL()
- setImageLink(imageURL)
- }
- }, [username, data])
+ // Removed: drawing happens inside Heatmap component tied to its canvas And inside Heatmap: - useEffect(() => {
+ useEffect(() => {
if (canvasRef.current && data?.years?.length) {
drawContributions(canvasRef.current, {
data,
username,
themeName: isDarkMode ? 'dark' : 'light',
})
const imageURL = canvasRef.current.toDataURL()
setImageLink(imageURL)
}
- }, [isDarkMode])
+ }, [isDarkMode, data, username]) Also applies to: 74-81, 139-155 |
||
|
||
const { data: graphQLData, error: graphQLRequestError } = useQuery(GET_USER_DATA, { | ||
const { data: graphQLData, error: graphQLRequestError } = useQuery(GetUserDataDocument, { | ||
variables: { key: memberKey }, | ||
}) | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Fix: spinner can hang forever on errors — gate loading off hook
loading
flags, not data presence.Using
!data
to infer loading causes an indefinite spinner when a request errors (no data ever arrives). Readloading
from eachuseQuery
and deriveisLoading
from those flags.Apply:
Also applies to: 56-66, 95-103
🤖 Prompt for AI Agents