Skip to content
Draft
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: 1 addition & 1 deletion packages/vinext/src/cloudflare/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
*/

export { KVCacheHandler } from "./kv-cache-handler.js";
export { runTPR, type TPROptions, type TPRResult } from "./tpr.js";
export { runTPR } from "./tpr.js";
20 changes: 0 additions & 20 deletions packages/vinext/src/entries/app-ssr-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,6 @@ import * as _clientRefs from "virtual:vite-rsc/client-references";

let _clientRefsPreloaded = false;

/**
* Collect all chunks from a ReadableStream into an array of text strings.
* Used to capture the RSC payload for embedding in HTML.
* The RSC flight protocol is text-based (line-delimited key:value pairs),
* so we decode to text strings instead of byte arrays — this is dramatically
* more compact when JSON-serialized into inline <script> tags.
*/
async function collectStreamChunks(stream) {
const reader = stream.getReader();
const decoder = new TextDecoder();
const chunks = [];
while (true) {
const { done, value } = await reader.read();
if (done) break;
// Decode Uint8Array to text string for compact JSON serialization
chunks.push(decoder.decode(value, { stream: true }));
}
return chunks;
}

// React 19 dev-mode workaround (see VinextFlightRoot in handleSsr):
//
// In dev, Flight error decoding in react-server-dom-webpack/client.edge
Expand Down
47 changes: 0 additions & 47 deletions packages/vinext/src/entries/pages-server-entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -536,53 +536,6 @@ function collectAssetTags(manifest, moduleIds) {
return tags.join("\\n ");
}

// i18n helpers
function extractLocale(url) {
if (!i18nConfig) return { locale: undefined, url, hadPrefix: false };
const pathname = url.split("?")[0];
const parts = pathname.split("/").filter(Boolean);
const query = url.includes("?") ? url.slice(url.indexOf("?")) : "";
if (parts.length > 0 && i18nConfig.locales.includes(parts[0])) {
const locale = parts[0];
const rest = "/" + parts.slice(1).join("/");
return { locale, url: (rest || "/") + query, hadPrefix: true };
}
return { locale: i18nConfig.defaultLocale, url, hadPrefix: false };
}

function detectLocaleFromHeaders(headers) {
if (!i18nConfig) return null;
const acceptLang = headers.get("accept-language");
if (!acceptLang) return null;
const langs = acceptLang.split(",").map(function(part) {
const pieces = part.trim().split(";");
const q = pieces[1] ? parseFloat(pieces[1].replace("q=", "")) : 1;
return { lang: pieces[0].trim().toLowerCase(), q: q };
}).sort(function(a, b) { return b.q - a.q; });
for (let k = 0; k < langs.length; k++) {
const lang = langs[k].lang;
for (let j = 0; j < i18nConfig.locales.length; j++) {
if (i18nConfig.locales[j].toLowerCase() === lang) return i18nConfig.locales[j];
}
const prefix = lang.split("-")[0];
for (let j = 0; j < i18nConfig.locales.length; j++) {
const loc = i18nConfig.locales[j].toLowerCase();
if (loc === prefix || loc.startsWith(prefix + "-")) return i18nConfig.locales[j];
}
}
return null;
}

function parseCookieLocaleFromHeader(cookieHeader) {
if (!i18nConfig || !cookieHeader) return null;
const match = cookieHeader.match(/(?:^|;\\s*)NEXT_LOCALE=([^;]*)/);
if (!match) return null;
var value;
try { value = decodeURIComponent(match[1].trim()); } catch (e) { return null; }
if (i18nConfig.locales.indexOf(value) !== -1) return value;
return null;
}

// Lightweight req/res facade for getServerSideProps and API routes.
// Next.js pages expect ctx.req/ctx.res with Node-like shapes.
function createReqRes(request, url, query, body) {
Expand Down
4 changes: 2 additions & 2 deletions packages/vinext/src/routing/file-matcher.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { glob } from "node:fs/promises";

export const DEFAULT_PAGE_EXTENSIONS = ["tsx", "ts", "jsx", "js"] as const;
const DEFAULT_PAGE_EXTENSIONS = ["tsx", "ts", "jsx", "js"] as const;

function escapeRegex(value: string): string {
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
Expand All @@ -18,7 +18,7 @@ export function normalizePageExtensions(pageExtensions?: readonly string[] | nul
return filtered.length > 0 ? [...filtered] : [...DEFAULT_PAGE_EXTENSIONS];
}

export function buildExtensionGlob(stem: string, extensions: readonly string[]): string {
function buildExtensionGlob(stem: string, extensions: readonly string[]): string {
if (extensions.length === 1) {
return `${stem}.${extensions[0]}`;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/vinext/src/routing/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
* E.g. /:locale/blog/:path+ (with infix "blog") correctly beats /:locale/:path+
* even when both share the same "locale-test" static prefix.
*/
export function routePrecedence(pattern: string): number {
function routePrecedence(pattern: string): number {
const parts = pattern.split("/").filter(Boolean);
let score = 0;

Expand Down Expand Up @@ -105,7 +105,7 @@ export function decodeRouteSegment(segment: string): string {
/**
* Strict variant for request pipelines that should reject malformed percent-encoding.
*/
export function decodeRouteSegmentStrict(segment: string): string {
function decodeRouteSegmentStrict(segment: string): string {
return encodePathDelimiters(decodeURIComponent(segment));
}

Expand Down
3 changes: 0 additions & 3 deletions packages/vinext/src/shims/internal/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,3 @@ export function getURL(): string {
}
return "http://localhost/";
}

export const SP = typeof performance !== "undefined";
export const ST = SP && typeof performance.mark === "function";
67 changes: 0 additions & 67 deletions tests/__snapshots__/entry-templates.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -18395,26 +18395,6 @@ import * as _clientRefs from "virtual:vite-rsc/client-references";

let _clientRefsPreloaded = false;

/**
* Collect all chunks from a ReadableStream into an array of text strings.
* Used to capture the RSC payload for embedding in HTML.
* The RSC flight protocol is text-based (line-delimited key:value pairs),
* so we decode to text strings instead of byte arrays — this is dramatically
* more compact when JSON-serialized into inline <script> tags.
*/
async function collectStreamChunks(stream) {
const reader = stream.getReader();
const decoder = new TextDecoder();
const chunks = [];
while (true) {
const { done, value } = await reader.read();
if (done) break;
// Decode Uint8Array to text string for compact JSON serialization
chunks.push(decoder.decode(value, { stream: true }));
}
return chunks;
}

// React 19 dev-mode workaround (see VinextFlightRoot in handleSsr):
//
// In dev, Flight error decoding in react-server-dom-webpack/client.edge
Expand Down Expand Up @@ -19328,53 +19308,6 @@ function collectAssetTags(manifest, moduleIds) {
return tags.join("\\n ");
}

// i18n helpers
function extractLocale(url) {
if (!i18nConfig) return { locale: undefined, url, hadPrefix: false };
const pathname = url.split("?")[0];
const parts = pathname.split("/").filter(Boolean);
const query = url.includes("?") ? url.slice(url.indexOf("?")) : "";
if (parts.length > 0 && i18nConfig.locales.includes(parts[0])) {
const locale = parts[0];
const rest = "/" + parts.slice(1).join("/");
return { locale, url: (rest || "/") + query, hadPrefix: true };
}
return { locale: i18nConfig.defaultLocale, url, hadPrefix: false };
}

function detectLocaleFromHeaders(headers) {
if (!i18nConfig) return null;
const acceptLang = headers.get("accept-language");
if (!acceptLang) return null;
const langs = acceptLang.split(",").map(function(part) {
const pieces = part.trim().split(";");
const q = pieces[1] ? parseFloat(pieces[1].replace("q=", "")) : 1;
return { lang: pieces[0].trim().toLowerCase(), q: q };
}).sort(function(a, b) { return b.q - a.q; });
for (let k = 0; k < langs.length; k++) {
const lang = langs[k].lang;
for (let j = 0; j < i18nConfig.locales.length; j++) {
if (i18nConfig.locales[j].toLowerCase() === lang) return i18nConfig.locales[j];
}
const prefix = lang.split("-")[0];
for (let j = 0; j < i18nConfig.locales.length; j++) {
const loc = i18nConfig.locales[j].toLowerCase();
if (loc === prefix || loc.startsWith(prefix + "-")) return i18nConfig.locales[j];
}
}
return null;
}

function parseCookieLocaleFromHeader(cookieHeader) {
if (!i18nConfig || !cookieHeader) return null;
const match = cookieHeader.match(/(?:^|;\\s*)NEXT_LOCALE=([^;]*)/);
if (!match) return null;
var value;
try { value = decodeURIComponent(match[1].trim()); } catch (e) { return null; }
if (i18nConfig.locales.indexOf(value) !== -1) return value;
return null;
}

// Lightweight req/res facade for getServerSideProps and API routes.
// Next.js pages expect ctx.req/ctx.res with Node-like shapes.
function createReqRes(request, url, query, body) {
Expand Down
Loading