Skip to content

Support scoped server loaders for nested Pages layouts #882

Open

Description

@karthickeyan-dev

Our admin layout displays an unread-report count shared by several nested pages. Middleware reads it before each request and puts it in shared. When a page action marks a report as read, the action’s page response still contains the pre-action count unless the handler refreshes it explicitly. Each action that changes the count has to know about the sidebar, and the admin-only field appears in the application-wide shared type.

What I checked

In a four-file React Pages fixture with void@1.11.0, I ran the installed page scanner with these files:

pages/admin/layout.tsx
pages/admin/layout.server.ts   // exports loader
pages/admin/index.tsx
pages/admin/index.server.ts    // exports loader

The page entry recorded serverPath: "admin/index.server.ts" and methods: ["loader"]. The layout entry recorded its directory and component path only. The Pages actions guide also documents that middleware does not run a second time when the action rerenders the page.

Request

Let a layout supply a server loader, for example through pages/admin/layout.server.ts, and expose the inferred result to that layout. Run it for requests that render a descendant page, including a page refresh after an action, so its data reflects the completed mutation. Pages outside that layout should incur no read. For the sidebar case this would let the layout own its count and let each page action own its mutation.

The existing workaround is to recompute the shared field in the action before returning, or redirect to make a fresh request.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions