Skip to content

Commit 35b107a

Browse files
authored
fix: prefetch causing stale data (#9020)
Potentially fixes #9012 by disabling prefetch for all Next.js `Link` component usage. With prefetch left as the default and _on_, there were cases where the prefetch could fetch stale data for Edit routes. Then, when navigating to the Edit route, the data could be stale. In addition, I think there is some strangeness happening on the Next.js side where prefetched data might still come from the router cache even though router cache is disabled. This fix should be done regardless, but I suspect it will solve for a lot of stale data issues.
1 parent 6b9f178 commit 35b107a

File tree

12 files changed

+36
-9
lines changed

12 files changed

+36
-9
lines changed

packages/next/src/elements/DocumentHeader/Tabs/Tab/TabLink.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ export const DocumentTabLink: React.FC<{
6767
<Link
6868
className={`${baseClass}__link`}
6969
href={!isActive || href !== pathname ? hrefWithLocale : ''}
70+
prefetch={false}
7071
{...(newTab && { rel: 'noopener noreferrer', target: '_blank' })}
7172
tabIndex={isActive ? -1 : 0}
7273
>

packages/next/src/elements/Nav/index.client.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ export const DefaultNavClient: React.FC = () => {
9898
href={href}
9999
id={id}
100100
key={i}
101+
prefetch={Link ? false : undefined}
101102
tabIndex={!navOpen ? -1 : undefined}
102103
>
103104
{activeCollection && <div className={`${baseClass}__link-indicator`} />}

packages/next/src/views/ForgotPassword/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ export const ForgotPasswordView: React.FC<AdminViewProps> = ({ initPageResult })
4242
adminRoute,
4343
path: accountRoute,
4444
})}
45+
prefetch={false}
4546
>
4647
{children}
4748
</Link>
@@ -68,6 +69,7 @@ export const ForgotPasswordView: React.FC<AdminViewProps> = ({ initPageResult })
6869
adminRoute,
6970
path: loginRoute,
7071
})}
72+
prefetch={false}
7173
>
7274
{i18n.t('authentication:backToLogin')}
7375
</Link>

packages/next/src/views/Login/LoginForm/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ export const LoginForm: React.FC<{
105105
adminRoute,
106106
path: forgotRoute,
107107
})}
108+
prefetch={false}
108109
>
109110
{t('authentication:forgotPasswordQuestion')}
110111
</Link>

packages/next/src/views/ResetPassword/index.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export const ResetPassword: React.FC<AdminViewProps> = ({ initPageResult, params
4848
adminRoute,
4949
path: accountRoute,
5050
})}
51+
prefetch={false}
5152
>
5253
{children}
5354
</Link>
@@ -75,6 +76,7 @@ export const ResetPassword: React.FC<AdminViewProps> = ({ initPageResult, params
7576
adminRoute,
7677
path: loginRoute,
7778
})}
79+
prefetch={false}
7880
>
7981
{i18n.t('authentication:backToLogin')}
8082
</Link>

packages/next/src/views/Versions/cells/CreatedAt/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const CreatedAtCell: React.FC<CreatedAtCellProps> = ({
4747
}
4848

4949
return (
50-
<Link href={to}>
50+
<Link href={to} prefetch={false}>
5151
{cellData &&
5252
formatDate({ date: cellData as Date | number | string, i18n, pattern: dateFormat })}
5353
</Link>

packages/ui/src/elements/AppHeader/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ export const AppHeader: React.FC = () => {
9494
aria-label={t('authentication:account')}
9595
className={`${baseClass}__account`}
9696
href={formatAdminURL({ adminRoute, path: accountRoute })}
97+
prefetch={Link ? false : undefined}
9798
tabIndex={0}
9899
>
99100
<Account />

packages/ui/src/elements/Button/index.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, Props>((
121121
}
122122

123123
let buttonElement
124+
let prefetch
124125

125126
switch (el) {
126127
case 'anchor':
@@ -147,10 +148,12 @@ export const Button = forwardRef<HTMLAnchorElement | HTMLButtonElement, Props>((
147148

148149
if (disabled) {
149150
LinkTag = 'div'
151+
} else {
152+
prefetch = false
150153
}
151154

152155
buttonElement = (
153-
<LinkTag {...buttonProps} href={to || url} to={to || url}>
156+
<LinkTag {...buttonProps} href={to || url} prefetch={prefetch} to={to || url}>
154157
<ButtonContents icon={icon} showTooltip={showTooltip} tooltip={tooltip}>
155158
{children}
156159
</ButtonContents>

packages/ui/src/elements/Logout/index.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,21 @@ const DefaultLogout: React.FC<{
2626
const basePath = process.env.NEXT_BASE_PATH ?? ''
2727
const LinkElement = Link || 'a'
2828

29+
const props = {
30+
'aria-label': t('authentication:logOut'),
31+
className: `${baseClass}__log-out`,
32+
prefetch: Link ? false : undefined,
33+
tabIndex,
34+
}
35+
2936
return (
3037
<LinkElement
31-
aria-label={t('authentication:logOut')}
32-
className={`${baseClass}__log-out`}
38+
{...props}
3339
href={formatAdminURL({
3440
adminRoute,
3541
basePath,
3642
path: logoutRoute,
3743
})}
38-
tabIndex={tabIndex}
3944
>
4045
<LogOutIcon />
4146
</LinkElement>

packages/ui/src/elements/Popup/PopupButtonList/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export const Button: React.FC<MenuButtonProps> = ({
6060
onClick(e)
6161
}
6262
}}
63+
prefetch={false}
6364
>
6465
{children}
6566
</Link>

0 commit comments

Comments
 (0)