8000 Preloading nested or sibling routes results in an error · Issue #12628 · react-navigation/react-navigation · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Preloading nested or sibling routes results in an error #12628

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

Open
2 of 12 tasks
Bram-dc opened this issue Jun 5, 2025 · 3 comments
Open
2 of 12 tasks

Preloading nested or sibling routes results in an error #12628

Bram-dc opened this issue Jun 5, 2025 · 3 comments

Comments

@Bram-dc
Copy link
Contributor
Bram-dc commented Jun 5, 2025

Current behavior

I am trying to make a component that preloads the route when hovering over a <Link />.

When doing this in a nested route (or for sibling routes). The app crashes.

Expected behavior

The route should be preloaded.

This is the component example I am trying to achieve. (and was working in earlier versions of react-navigation)

import { useNavigation } from '@react-navigation/native'
import { useCallback } from 'react'
import { Pressable } from 'react-native'

type LinkProps = {
	href: string
	children?: React.ReactNode
}

const Link = ({ href, children }: LinkProps) => {
	const navigation = useNavigation()
	const { buildAction } = useLinkBuilder()

	const action = buildAction(href)

	const linkProps = useLinkProps({ href, action })

	const prefetchRoute = useCallback(() => {
		if (action.type !== 'NAVIGATE') {
			return
		}

		const preloadAction = CommonActions.preload(action.payload.name, action.payload.params)

		navigation.dispatch(preloadAction)
	}, [navigation, action])

	return (
		<Pressable {...linkProps} 
			{children}
		</Pressable>
	)
}

export default Link

Reproduction

https://github.com/Bram-dc/preload-bug

Platform

  • Android
  • iOS
  • Web
  • Windows
  • MacOS

Packages

  • @react-navigation/bottom-tabs
  • @react-navigation/drawer
  • @react-navigation/material-top-tabs
  • @react-navigation/stack
  • @react-navigation/native-stack
  • react-native-drawer-layout
  • react-native-tab-view

Environment

  • [] I've removed the packages that I don't use
package version
@react-navigation/native 7.0.14
@react-navigation/native-stack 7.2.0
react-native 0.79.3
npm 11.3.0
@Bram-dc Bram-dc added the bug label Jun 5, 2025
Copy link
github-actions bot commented Jun 5, 2025

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

  • @react-navigation/native (found: 7.0.14, latest: 7.1.10)

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

1 similar comment
Copy link
github-actions bot commented Jun 5, 2025

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

  • @react-navigation/native (found: 7.0.14, latest: 7.1.10)

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

Copy link
github-actions bot commented Jun 5, 2025

Couldn't find version numbers for the following packages in the issue:

  • @react-navigation/stack

Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.

The versions mentioned in the issue for the following packages differ from the latest versions on npm:

  • @react-navigation/native (found: 7.0.14, latest: 7.1.10)

Can you verify that the issue still exists after upgrading to the latest versions of these packages?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant
0