Skip to content
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

Add experimental touchstart flag for testing #61747

Merged
merged 2 commits into from
Feb 7, 2024
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
3 changes: 3 additions & 0 deletions packages/next/src/build/webpack/plugins/define-env-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ export function getDefineEnv({
'process.env.__NEXT_WEB_VITALS_ATTRIBUTION': JSON.stringify(
config.experimental.webVitalsAttribution
),
'process.env.__NEXT_LINK_NO_TOUCH_START': JSON.stringify(
config.experimental.linkNoTouchStart
),
'process.env.__NEXT_ASSET_PREFIX': JSON.stringify(config.assetPrefix),
...(isNodeOrEdgeCompilation
? {
Expand Down
76 changes: 39 additions & 37 deletions packages/next/src/client/link.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkPropsReal>(
])

const childProps: {
onTouchStart: React.TouchEventHandler<HTMLAnchorElement>
onTouchStart?: React.TouchEventHandler<HTMLAnchorElement>
onMouseEnter: React.MouseEventHandler<HTMLAnchorElement>
onClick: React.MouseEventHandler<HTMLAnchorElement>
href?: string
Expand Down Expand Up @@ -680,43 +680,45 @@ const Link = React.forwardRef<HTMLAnchorElement, LinkPropsReal>(
isAppRouter
)
},
onTouchStart(e) {
if (!legacyBehavior && typeof onTouchStartProp === 'function') {
onTouchStartProp(e)
}

if (
legacyBehavior &&
child.props &&
typeof child.props.onTouchStart === 'function'
) {
child.props.onTouchStart(e)
}

if (!router) {
return
}

if (!prefetchEnabled && isAppRouter) {
return
}

prefetch(
router,
href,
as,
{
locale,
priority: true,
// @see {https://github.com/vercel/next.js/discussions/40268?sort=top#discussioncomment-3572642}
bypassPrefetchedCheck: true,
},
{
kind: appPrefetchKind,
onTouchStart: process.env.__NEXT_LINK_NO_TOUCH_START
? undefined
: function onTouchStart(e) {
if (!legacyBehavior && typeof onTouchStartProp === 'function') {
onTouchStartProp(e)
}

if (
legacyBehavior &&
child.props &&
typeof child.props.onTouchStart === 'function'
) {
child.props.onTouchStart(e)
}

if (!router) {
return
}

if (!prefetchEnabled && isAppRouter) {
return
}

prefetch(
router,
href,
as,
{
locale,
priority: true,
// @see {https://github.com/vercel/next.js/discussions/40268?sort=top#discussioncomment-3572642}
bypassPrefetchedCheck: true,
},
{
kind: appPrefetchKind,
},
isAppRouter
)
},
isAppRouter
)
},
}

// If child is an <a> tag and doesn't have a href attribute, or if the 'passHref' property is
Expand Down
1 change: 1 addition & 0 deletions packages/next/src/server/config-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ export const configSchema: zod.ZodType<NextConfig> = z.lazy(() =>
gzipSize: z.boolean().optional(),
isrFlushToDisk: z.boolean().optional(),
largePageDataBytes: z.number().optional(),
linkNoTouchStart: z.boolean().optional(),
manualClientBasePath: z.boolean().optional(),
middlewarePrefetch: z.enum(['strict', 'flexible']).optional(),
nextScriptWorkers: z.boolean().optional(),
Expand Down
2 changes: 2 additions & 0 deletions packages/next/src/server/config-shared.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export interface NextJsWebpackConfig {
}

export interface ExperimentalConfig {
linkNoTouchStart?: boolean
caseSensitiveRoutes?: boolean
useDeploymentId?: boolean
useDeploymentIdServerActions?: boolean
Expand Down Expand Up @@ -815,6 +816,7 @@ export const defaultConfig: NextConfig = {
experimental: {
serverMinification: true,
serverSourceMaps: false,
linkNoTouchStart: false,
caseSensitiveRoutes: false,
useDeploymentId: false,
deploymentId: undefined,
Expand Down