11import type { NativeStackHeaderItem } from "@react-navigation/native-stack" ;
2+ import { NavigationContext } from "@react-navigation/native" ;
23import { act , createContext , startTransition , Suspense , type ReactElement } from "react" ;
34import { createRoot , type Root } from "react-dom/client" ;
45import { afterEach , expect , it , vi } from "vite-plus/test" ;
@@ -20,7 +21,7 @@ const harness = vi.hoisted(() => ({
2021// Navigation, the header renders again only when the options are no longer shallowly equal.
2122vi . mock ( "@react-navigation/native" , async ( ) => {
2223 // vi.mock factories run before the file's imports.
23- const { createContext } = await vi . importActual < typeof import ( "react" ) > ( "react" ) ;
24+ const { createContext, use } = await vi . importActual < typeof import ( "react" ) > ( "react" ) ;
2425 const navigation = {
2526 setOptions ( options : HeaderOptions ) {
2627 harness . setOptionsCalls += 1 ;
@@ -39,15 +40,23 @@ vi.mock("@react-navigation/native", async () => {
3940 [ ] ;
4041 } ,
4142 } ;
43+ const navigationContext = createContext < typeof navigation | undefined > ( navigation ) ;
4244 return {
4345 // Outside a workspace tab slot the header writes to the route's navigation.
4446 NavigationRouteContext : createContext ( undefined ) ,
45- useNavigation : ( ) => navigation ,
47+ NavigationContext : navigationContext ,
48+ useNavigation : ( ) =>
49+ use ( navigationContext ) ?? {
50+ setOptions ( ) {
51+ throw new Error ( "Cannot call setOptions outside a screen" ) ;
52+ } ,
53+ } ,
4654 useRoute : ( ) => ( { key : "file" , name : "ThreadFile" , params : harness . params } ) ,
4755 } ;
4856} ) ;
4957
5058import { NativeHeaderToolbar } from "./NativeHeaderToolbar" ;
59+ import { NativeStackScreenOptions } from "./StackHeader" ;
5160
5261let root : Root | null = null ;
5362
@@ -97,6 +106,19 @@ afterEach(() => {
97106 vi . unstubAllGlobals ( ) ;
98107} ) ;
99108
109+ it ( "does not configure a native screen from an embedded pane" , ( ) => {
110+ vi . stubGlobal ( "IS_REACT_ACT_ENVIRONMENT" , true ) ;
111+ root = createRoot ( document . createElement ( "div" ) ) ;
112+ act ( ( ) =>
113+ root ! . render (
114+ < NavigationContext value = { undefined } >
115+ < NativeStackScreenOptions options = { { headerShown : false } } />
116+ </ NavigationContext > ,
117+ ) ,
118+ ) ;
119+ expect ( harness . setOptionsCalls ) . toBe ( 0 ) ;
120+ } ) ;
121+
100122it . each ( [ "left" , "right" , "bottom" ] as const ) (
101123 "dispatches retained %s actions to the latest committed handlers without registering again" ,
102124 ( placement ) => {
0 commit comments