Skip to content
Open
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
2 changes: 2 additions & 0 deletions packages/vinext/src/client/vinext-next-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export type VinextNextData = {
pageModuleUrl?: string;
/** Absolute URL of the `_app` module for dynamic import. */
appModuleUrl?: string;
/** True when the Pages Router server has middleware/proxy configured. */
hasMiddleware?: boolean;
};
} & NEXT_DATA;

Expand Down
3 changes: 3 additions & 0 deletions packages/vinext/src/entries/pages-server-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ const i18nConfig = ${i18nConfigJson};
// match _next/data requests against the embedded buildId without needing
// to load next.config.js at runtime.
export const buildId = ${buildIdJson};
const __hasMiddleware = ${JSON.stringify(Boolean(middlewarePath))};

// Full resolved config for production server (embedded at build time)
export const vinextConfig = ${vinextConfigJson};
Expand Down Expand Up @@ -675,6 +676,7 @@ async function _renderPage(request, url, manifest, middlewareHeaders, options) {
safeJsonStringify,
sanitizeDestination: sanitizeDestinationLocal,
scriptNonce,
vinext: { hasMiddleware: __hasMiddleware },
triggerBackgroundRegeneration,
});
if (pageDataResult.kind === "response") {
Expand Down Expand Up @@ -795,6 +797,7 @@ async function _renderPage(request, url, manifest, middlewareHeaders, options) {
routeUrl,
safeJsonStringify,
scriptNonce,
vinext: { hasMiddleware: __hasMiddleware },
});
} catch (e) {
console.error("[vinext] SSR error:", e);
Expand Down
5 changes: 4 additions & 1 deletion packages/vinext/src/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ declare global {
* client-side navigation.
*/
__VINEXT_APP__:
| React.ComponentType<{ Component: React.ComponentType<unknown>; pageProps: unknown }>
| React.ComponentType<{
Component: React.ComponentType<Record<string, unknown>>;
pageProps: unknown;
}>
| undefined;

/**
Expand Down
1 change: 1 addition & 0 deletions packages/vinext/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3317,6 +3317,7 @@ export default function vinext(options: VinextOptions = {}): PluginOption[] {
fileMatcher,
nextConfig?.basePath ?? "",
nextConfig?.trailingSlash ?? false,
middlewarePath !== null,
);
const mwStatus = req.__vinextMiddlewareStatus;

Expand Down
3 changes: 3 additions & 0 deletions packages/vinext/src/server/dev-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export function createSSRHandler(
fileMatcher?: ValidFileMatcher,
basePath = "",
trailingSlash = false,
hasMiddleware = false,
) {
const matcher = fileMatcher ?? createValidFileMatcher();

Expand Down Expand Up @@ -758,6 +759,7 @@ export function createSSRHandler(
__vinext: {
pageModuleUrl: regenPageUrl,
appModuleUrl: regenAppUrl,
hasMiddleware,
},
})}${i18nConfig ? `;window.__VINEXT_LOCALE__=${safeJsonStringify(locale ?? currentDefaultLocale)};window.__VINEXT_LOCALES__=${safeJsonStringify(i18nConfig.locales)};window.__VINEXT_DEFAULT_LOCALE__=${safeJsonStringify(currentDefaultLocale)}` : ""}</script>`;

Expand Down Expand Up @@ -1032,6 +1034,7 @@ hydrate();
__vinext: {
pageModuleUrl,
appModuleUrl,
hasMiddleware,
},
})}${i18nConfig ? `;window.__VINEXT_LOCALE__=${safeJsonStringify(locale ?? currentDefaultLocale)};window.__VINEXT_LOCALES__=${safeJsonStringify(i18nConfig.locales)};window.__VINEXT_DEFAULT_LOCALE__=${safeJsonStringify(currentDefaultLocale)}` : ""}`,
scriptNonce,
Expand Down
5 changes: 5 additions & 0 deletions packages/vinext/src/server/pages-page-data.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ReactNode } from "react";
import type { Route } from "../routing/pages-router.js";
import type { VinextNextData } from "../client/vinext-next-data.js";
import { normalizeStaticPathname } from "../routing/route-pattern.js";
import type { CachedPagesValue, CacheControlMetadata } from "vinext/shims/cache";
import { buildCachedRevalidateCacheControl } from "./cache-control.js";
Expand Down Expand Up @@ -93,6 +94,7 @@ type RenderPagesIsrHtmlOptions = {
renderIsrPassToStringAsync: (element: ReactNode) => Promise<string>;
routePattern: string;
safeJsonStringify: (value: unknown) => string;
vinext?: VinextNextData["__vinext"];
};

export type ResolvePagesPageDataOptions = {
Expand Down Expand Up @@ -131,6 +133,7 @@ export type ResolvePagesPageDataOptions = {
safeJsonStringify: (value: unknown) => string;
sanitizeDestination: (destination: string) => string;
scriptNonce?: string;
vinext?: VinextNextData["__vinext"];
triggerBackgroundRegeneration: (
key: string,
renderFn: () => Promise<void>,
Expand Down Expand Up @@ -297,6 +300,7 @@ export async function renderPagesIsrHtml(options: RenderPagesIsrHtmlOptions): Pr
params: options.params,
routePattern: options.routePattern,
safeJsonStringify: options.safeJsonStringify,
vinext: options.vinext,
});

return rewritePagesCachedHtml(options.cachedHtml, freshBody, nextDataScript);
Expand Down Expand Up @@ -475,6 +479,7 @@ export async function resolvePagesPageData(
renderIsrPassToStringAsync: options.renderIsrPassToStringAsync,
routePattern: options.routePattern,
safeJsonStringify: options.safeJsonStringify,
vinext: options.vinext,
});

await options.isrSet(
Expand Down
2 changes: 2 additions & 0 deletions packages/vinext/src/server/pages-page-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ type RenderPagesPageResponseOptions = {
routeUrl: string;
safeJsonStringify: (value: unknown) => string;
scriptNonce?: string;
vinext?: VinextNextData["__vinext"];
};

function buildPagesFontHeadHtml(
Expand Down Expand Up @@ -318,6 +319,7 @@ export async function renderPagesPageResponse(
routePattern: options.routePattern,
safeJsonStringify: options.safeJsonStringify,
scriptNonce: options.scriptNonce,
vinext: options.vinext,
});
const bodyMarker = "<!--VINEXT_STREAM_BODY-->";
// Render the page FIRST so that <Head> and other SSR state collectors
Expand Down
Loading
Loading