@@ -100,7 +100,7 @@ function scanDirectory(directory: string, basePath: string = ''): Route | null {
100100 : `${ layoutComponentName } `
101101
102102 route . Component = `withLoaderData((props) => <${ componentName } children={<Outlet />} {...props} />, "${ componentName } ")`
103- route . loader = `loader`
103+ route . loader = `loader(" ${ componentName } ") `
104104 route . shouldRevalidate = `(args) => args.defaultShouldRevalidate`
105105
106106 if ( route . path === '/' ) {
@@ -132,7 +132,7 @@ function scanDirectory(directory: string, basePath: string = ''): Route | null {
132132 errorElement : '<ErrorElement standalone={false} />' ,
133133 lazy : `async () => {const i = await import(${ importPath } ).catch(() => {window.reload()}); return {Component: withLoaderData(i.default)}}` ,
134134 HydrateFallback : 'HydrateFallback' ,
135- loader : `loader`
135+ loader : `loader() `
136136 } )
137137
138138 pageFound = true
@@ -266,14 +266,23 @@ const HydrateFallback = () => {
266266function withLoaderData<T>(Component: React.ComponentType<{ data: T }>, name?: string) {
267267 return function WithLoaderDataWrapper(props: T) {
268268 const dataClient = __PYLON_INTERNALS_DO_NOT_USE.useDataClient()
269- const {useQuery, useHydrateCache} = useMemo(() => dataClient.pageClient(), [])
270- const {cacheSnapshot, context} = __PYLON_ROUTER_INTERNALS_DO_NOT_USE.useLoaderData() || {};
269+ const pruningTarget = __PYLON_INTERNALS_DO_NOT_USE.useSSRPruning()
271270
271+ const {cacheSnapshot, context} = __PYLON_ROUTER_INTERNALS_DO_NOT_USE.useLoaderData() || {};
272272 const location = __PYLON_ROUTER_INTERNALS_DO_NOT_USE.useLocation()
273273 const [searchParams] = __PYLON_ROUTER_INTERNALS_DO_NOT_USE.useSearchParams()
274274 const searchParamsObject = Object.fromEntries(searchParams.entries())
275275 const params = __PYLON_ROUTER_INTERNALS_DO_NOT_USE.useParams()
276276
277+ // 1. Handle Transparent Ancestors
278+ // If we're optimized-rendering a specific layout, and THIS is not it,
279+ // we just act as a passthrough to skip THIS layout's logic/queries.
280+ if (pruningTarget && name !== pruningTarget) {
281+ return <Outlet />
282+ }
283+
284+ const {useQuery, useHydrateCache} = useMemo(() => dataClient.pageClient(), [])
285+
277286 if(cacheSnapshot) {
278287 useHydrateCache({cacheSnapshot})
279288 }
@@ -290,13 +299,17 @@ function withLoaderData<T>(Component: React.ComponentType<{ data: T }>, name?: s
290299 }
291300 }, [location.pathname, params, searchParamsObject, data, context])
292301
302+ // 2. Handle Pruning Target
303+ // If THIS is the target, we render it but clear its children (the Outlet).
304+ const children = pruningTarget && name === pruningTarget ? null : <Outlet />
305+
293306 return <__PYLON_INTERNALS_DO_NOT_USE.RouteDataProvider props={pageProps} name={name}>
294- <Component {...(props as any)} {...pageProps} />
307+ <Component {...(props as any)} {...pageProps} children={children} />
295308 </__PYLON_INTERNALS_DO_NOT_USE.RouteDataProvider>
296309 };
297310}
298311
299- const loader: __PYLON_ROUTER_INTERNALS_DO_NOT_USE.LoaderFunction = async ({ request }) => {
312+ const loader: (ref?: string) => __PYLON_ROUTER_INTERNALS_DO_NOT_USE.LoaderFunction = (ref) => async ({ request, ...args }) => {
300313 // 1. Skip if request is a JSON-only fetch (e.g., client-side route preloading)
301314 const acceptHeader = request.headers.get('accept')
302315 if (acceptHeader?.includes('application/json')) {
@@ -324,6 +337,9 @@ const loader: __PYLON_ROUTER_INTERNALS_DO_NOT_USE.LoaderFunction = async ({ requ
324337 }
325338
326339 headers.set('Accept', 'application/json') // Ensure the internal request gets JSON
340+ if(ref) {
341+ headers.set('X-Pylon-Route-Ref', ref)
342+ }
327343
328344 const response = await fetchToUse(url.pathname + url.search, {
329345 method: 'GET',
0 commit comments