nuxt-nightly 4.3.0-29435873.41a564d2 → 4.3.0-29436247.ecea7a86

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,3 @@
1
- import type { MatcherExport } from 'radix3';
2
1
  import type { H3Event } from 'h3';
3
2
  import type { NitroRouteRules } from 'nitropack/types';
4
3
  export interface NuxtAppManifestMeta {
@@ -6,15 +5,14 @@ export interface NuxtAppManifestMeta {
6
5
  timestamp: number;
7
6
  }
8
7
  export interface NuxtAppManifest extends NuxtAppManifestMeta {
9
- matcher: MatcherExport;
10
8
  prerendered: string[];
11
9
  }
12
10
  /** @since 3.7.4 */
13
11
  export declare function getAppManifest(): Promise<NuxtAppManifest>;
14
12
  /** @since 3.7.4 */
15
- export declare function getRouteRules(event: H3Event): Promise<NitroRouteRules>;
13
+ export declare function getRouteRules(event: H3Event): NitroRouteRules;
16
14
  export declare function getRouteRules(options: {
17
15
  path: string;
18
- }): Promise<Record<string, any>>;
16
+ }): Record<string, any>;
19
17
  /** @deprecated use `getRouteRules({ path })` instead */
20
- export declare function getRouteRules(url: string): Promise<Record<string, any>>;
18
+ export declare function getRouteRules(url: string): Record<string, any>;
@@ -1,10 +1,10 @@
1
- import { createMatcherFromExport, createRouter as createRadixRouter, toRouteMatcher } from "radix3";
2
1
  import { defu } from "defu";
3
2
  import { useNuxtApp, useRuntimeConfig } from "../nuxt.js";
4
3
  import { appManifest as isAppManifestEnabled } from "#build/nuxt.config.mjs";
5
4
  import { buildAssetsURL } from "#internal/nuxt/paths";
5
+ import _routeRulesMatcher from "#build/route-rules.mjs";
6
+ const routeRulesMatcher = _routeRulesMatcher;
6
7
  let manifest;
7
- let matcher;
8
8
  function fetchManifest() {
9
9
  if (!isAppManifestEnabled) {
10
10
  throw new Error("[nuxt] app manifest should be enabled with `experimental.appManifest`");
@@ -20,9 +20,7 @@ function fetchManifest() {
20
20
  responseType: "json"
21
21
  });
22
22
  }
23
- manifest.then((m) => {
24
- matcher = createMatcherFromExport(m.matcher);
25
- }).catch((e) => {
23
+ manifest.catch((e) => {
26
24
  console.error("[nuxt] Error fetching app manifest.", e);
27
25
  });
28
26
  return manifest;
@@ -36,22 +34,10 @@ export function getAppManifest() {
36
34
  }
37
35
  return manifest || fetchManifest();
38
36
  }
39
- export async function getRouteRules(arg) {
37
+ export function getRouteRules(arg) {
40
38
  const path = typeof arg === "string" ? arg : arg.path;
41
- if (import.meta.server) {
42
- useNuxtApp().ssrContext["~preloadManifest"] = true;
43
- const _routeRulesMatcher = toRouteMatcher(
44
- createRadixRouter({ routes: useRuntimeConfig().nitro.routeRules })
45
- );
46
- return defu({}, ..._routeRulesMatcher.matchAll(path).reverse());
47
- }
48
- await getAppManifest();
49
- if (!matcher) {
50
- console.error("[nuxt] Error creating app manifest matcher.", matcher);
51
- return {};
52
- }
53
39
  try {
54
- return defu({}, ...matcher.matchAll(path).reverse());
40
+ return defu({}, ...routeRulesMatcher("", path).map((r) => r.data).reverse());
55
41
  } catch (e) {
56
42
  console.error("[nuxt] Error matching route rules.", e);
57
43
  return {};
@@ -82,18 +82,19 @@ async function _importPayload(payloadURL) {
82
82
  }
83
83
  export async function isPrerendered(url = useRoute().path) {
84
84
  const nuxtApp = useNuxtApp();
85
+ const rules = getRouteRules({ path: url });
86
+ if (rules.redirect) {
87
+ return false;
88
+ }
89
+ if (rules.prerender) {
90
+ return true;
91
+ }
85
92
  if (!appManifest) {
86
93
  return !!nuxtApp.payload.prerenderedAt;
87
94
  }
88
95
  url = url === "/" ? url : url.replace(/\/$/, "");
89
96
  const manifest = await getAppManifest();
90
- if (manifest.prerendered.includes(url)) {
91
- return true;
92
- }
93
- return nuxtApp.runWithContext(async () => {
94
- const rules = await getRouteRules({ path: url });
95
- return !!rules.prerender && !rules.redirect;
96
- });
97
+ return manifest.prerendered.includes(url);
97
98
  }
98
99
  let payloadCache = null;
99
100
  export async function getNuxtClientPayload() {
@@ -1,11 +1,11 @@
1
1
  import { hasProtocol } from "ufo";
2
2
  import { defineNuxtRouteMiddleware } from "../composables/router.js";
3
3
  import { getRouteRules } from "../composables/manifest.js";
4
- export default defineNuxtRouteMiddleware(async (to) => {
4
+ export default defineNuxtRouteMiddleware((to) => {
5
5
  if (import.meta.server || import.meta.test) {
6
6
  return;
7
7
  }
8
- const rules = await getRouteRules({ path: to.path });
8
+ const rules = getRouteRules({ path: to.path });
9
9
  if (rules.redirect) {
10
10
  const path = rules.redirect.includes("#") ? rules.redirect : rules.redirect + to.hash;
11
11
  if (hasProtocol(path, { acceptRelative: true })) {
@@ -6,7 +6,6 @@ import { getRouteRules } from "../composables/manifest.js";
6
6
  import { clearError, showError } from "../composables/error.js";
7
7
  import { navigateTo } from "../composables/router.js";
8
8
  import { globalMiddleware } from "#build/middleware";
9
- import { appManifest as isAppManifestEnabled } from "#build/nuxt.config.mjs";
10
9
  function getRouteFromPath(fullPath) {
11
10
  const route = fullPath && typeof fullPath === "object" ? fullPath : {};
12
11
  if (typeof fullPath === "object") {
@@ -161,19 +160,17 @@ export default defineNuxtPlugin({
161
160
  nuxtApp._processingMiddleware = true;
162
161
  if (import.meta.client || !nuxtApp.ssrContext?.islandContext) {
163
162
  const middlewareEntries = /* @__PURE__ */ new Set([...globalMiddleware, ...nuxtApp._middleware.global]);
164
- if (isAppManifestEnabled) {
165
- const routeRules = await nuxtApp.runWithContext(() => getRouteRules({ path: to.path }));
166
- if (routeRules.appMiddleware) {
167
- for (const key in routeRules.appMiddleware) {
168
- const guard = nuxtApp._middleware.named[key];
169
- if (!guard) {
170
- return;
171
- }
172
- if (routeRules.appMiddleware[key]) {
173
- middlewareEntries.add(guard);
174
- } else {
175
- middlewareEntries.delete(guard);
176
- }
163
+ const routeRules = getRouteRules({ path: to.path });
164
+ if (routeRules.appMiddleware) {
165
+ for (const key in routeRules.appMiddleware) {
166
+ const guard = nuxtApp._middleware.named[key];
167
+ if (!guard) {
168
+ continue;
169
+ }
170
+ if (routeRules.appMiddleware[key]) {
171
+ middlewareEntries.add(guard);
172
+ } else {
173
+ middlewareEntries.delete(guard);
177
174
  }
178
175
  }
179
176
  }
package/dist/index.mjs CHANGED
@@ -25,7 +25,7 @@ import { addDependency } from 'nypm';
25
25
  import { reverseResolveAlias, filename, resolveAlias } from 'pathe/utils';
26
26
  import { createRoutesContext } from 'unplugin-vue-router';
27
27
  import { resolveOptions } from 'unplugin-vue-router/options';
28
- import { toRouteMatcher, createRouter } from 'radix3';
28
+ import { createRouter, addRoute, findAllRoutes } from 'rou3';
29
29
  import { fileURLToPath, pathToFileURL } from 'node:url';
30
30
  import { runInNewContext } from 'node:vm';
31
31
  import { klona } from 'klona';
@@ -1460,9 +1460,12 @@ const pagesModule = defineNuxtModule({
1460
1460
  ...toRou3Patterns(nuxt.apps.default?.pages || [])
1461
1461
  ];
1462
1462
  if (!nitro.options.static && !nitro.options.prerender.crawlLinks) {
1463
- const routeRulesMatcher = toRouteMatcher(createRouter({ routes: nitro.options.routeRules }));
1463
+ const routeRulesRouter = createRouter();
1464
+ for (const [route, rules] of Object.entries(nitro.options.routeRules)) {
1465
+ addRoute(routeRulesRouter, void 0, route, rules);
1466
+ }
1464
1467
  for (const route of prerenderRoutes) {
1465
- const rules = defu({}, ...routeRulesMatcher.matchAll(route).reverse());
1468
+ const rules = defu({}, ...findAllRoutes(routeRulesRouter, void 0, route).reverse());
1466
1469
  if (rules.prerender) {
1467
1470
  nitro.options.prerender.routes.push(route);
1468
1471
  }
@@ -1497,26 +1500,24 @@ const pagesModule = defineNuxtModule({
1497
1500
  });
1498
1501
  });
1499
1502
  }
1500
- if (nuxt.options.experimental.appManifest) {
1501
- nuxt.hook("pages:extend", (routes) => {
1502
- const nitro = useNitro();
1503
- let resolvedRoutes;
1504
- for (const [path, rule] of Object.entries(nitro.options.routeRules)) {
1505
- if (!rule.redirect) {
1506
- continue;
1507
- }
1508
- resolvedRoutes ||= routes.flatMap((route) => resolveRoutePaths(route));
1509
- if (resolvedRoutes.includes(path)) {
1510
- continue;
1511
- }
1512
- routes.push({
1513
- _sync: true,
1514
- path: path.replace(/\/[^/]*\*\*/, "/:pathMatch(.*)"),
1515
- file: componentStubPath
1516
- });
1503
+ nuxt.hook("pages:extend", (routes) => {
1504
+ const nitro = useNitro();
1505
+ let resolvedRoutes;
1506
+ for (const [path, rule] of Object.entries(nitro.options.routeRules)) {
1507
+ if (!rule.redirect) {
1508
+ continue;
1517
1509
  }
1518
- });
1519
- }
1510
+ resolvedRoutes ||= routes.flatMap((route) => resolveRoutePaths(route));
1511
+ if (resolvedRoutes.includes(path)) {
1512
+ continue;
1513
+ }
1514
+ routes.push({
1515
+ _sync: true,
1516
+ path: path.replace(/\/[^/]*\*\*/, "/:pathMatch(.*)"),
1517
+ file: componentStubPath
1518
+ });
1519
+ }
1520
+ });
1520
1521
  const extraPageMetaExtractionKeys = nuxt.options?.experimental?.extraPageMetaExtractionKeys || [];
1521
1522
  const extractedKeys = [
1522
1523
  ...defaultExtractionKeys,
@@ -3845,7 +3846,7 @@ function addDeclarationTemplates(ctx, options) {
3845
3846
  });
3846
3847
  }
3847
3848
 
3848
- const version = "4.3.0-29435873.41a564d2";
3849
+ const version = "4.3.0-29436247.ecea7a86";
3849
3850
  const pkg = {
3850
3851
  version: version};
3851
3852
 
@@ -4675,7 +4676,6 @@ const runtimeDependencies = [
4675
4676
  "unctx",
4676
4677
  "cookie-es",
4677
4678
  "perfect-debounce",
4678
- "radix3",
4679
4679
  "ohash",
4680
4680
  "pathe",
4681
4681
  "uncrypto"
@@ -5446,12 +5446,12 @@ Using \`${fallbackCompatibilityDate}\` as fallback. More info at: ${colors.under
5446
5446
  addPlugin(resolve(nuxt.options.appDir, "plugins/revive-payload.client"));
5447
5447
  addPlugin(resolve(nuxt.options.appDir, "plugins/revive-payload.server"));
5448
5448
  }
5449
+ addRouteMiddleware({
5450
+ name: "manifest-route-rule",
5451
+ path: resolve(nuxt.options.appDir, "middleware/route-rules"),
5452
+ global: true
5453
+ });
5449
5454
  if (nuxt.options.experimental.appManifest) {
5450
- addRouteMiddleware({
5451
- name: "manifest-route-rule",
5452
- path: resolve(nuxt.options.appDir, "middleware/manifest-route-rule"),
5453
- global: true
5454
- });
5455
5455
  if (nuxt.options.experimental.checkOutdatedBuildInterval !== false) {
5456
5456
  addPlugin(resolve(nuxt.options.appDir, "plugins/check-outdated-build.client"));
5457
5457
  }
@@ -1,13 +1,13 @@
1
1
  import { joinURL } from "ufo";
2
- import { createRouter as createRadixRouter, toRouteMatcher } from "radix3";
3
2
  import { defu } from "defu";
4
- import { defineNuxtPlugin, useRuntimeConfig } from "#app/nuxt";
3
+ import { defineNuxtPlugin } from "#app/nuxt";
5
4
  import { prerenderRoutes } from "#app/composables/ssr";
6
5
  import _routes from "#build/routes";
7
6
  import routerOptions, { hashMode } from "#build/router.options.mjs";
8
7
  import { crawlLinks } from "#build/nuxt.config.mjs";
8
+ import _routeRulesMatcher from "#build/route-rules.mjs";
9
+ const routeRulesMatcher = _routeRulesMatcher;
9
10
  let routes;
10
- let _routeRulesMatcher = void 0;
11
11
  export default defineNuxtPlugin(async () => {
12
12
  if (!import.meta.server || !import.meta.prerender || hashMode) {
13
13
  return;
@@ -15,17 +15,13 @@ export default defineNuxtPlugin(async () => {
15
15
  if (routes && !routes.length) {
16
16
  return;
17
17
  }
18
- const routeRules = useRuntimeConfig().nitro.routeRules;
19
- if (!crawlLinks && routeRules && Object.values(routeRules).some((r) => r.prerender)) {
20
- _routeRulesMatcher = toRouteMatcher(createRadixRouter({ routes: routeRules }));
21
- }
22
18
  routes ||= Array.from(processRoutes(await routerOptions.routes?.(_routes) ?? _routes));
23
19
  const batch = routes.splice(0, 10);
24
20
  prerenderRoutes(batch);
25
21
  });
26
22
  const OPTIONAL_PARAM_RE = /^\/?:.*(?:\?|\(\.\*\)\*)$/;
27
23
  function shouldPrerender(path) {
28
- return !_routeRulesMatcher || defu({}, ..._routeRulesMatcher.matchAll(path).reverse()).prerender;
24
+ return crawlLinks || defu({}, ...routeRulesMatcher("", path).map((r) => r.data).reverse()).prerender;
29
25
  }
30
26
  function processRoutes(routes2, currentPath = "/", routesToPrerender = /* @__PURE__ */ new Set()) {
31
27
  for (const route of routes2) {
@@ -6,7 +6,6 @@ import { getRouteRules } from "#app/composables/manifest";
6
6
  import { defineNuxtPlugin, useRuntimeConfig } from "#app/nuxt";
7
7
  import { clearError, createError, isNuxtError, showError, useError } from "#app/composables/error";
8
8
  import { navigateTo } from "#app/composables/router";
9
- import { appManifest as isAppManifestEnabled } from "#build/nuxt.config.mjs";
10
9
  import _routes, { handleHotUpdate } from "#build/routes";
11
10
  import routerOptions, { hashMode } from "#build/router.options.mjs";
12
11
  import { globalMiddleware, namedMiddleware } from "#build/middleware";
@@ -143,15 +142,13 @@ const plugin = defineNuxtPlugin({
143
142
  middlewareEntries.add(entry);
144
143
  }
145
144
  }
146
- if (isAppManifestEnabled) {
147
- const routeRules = await nuxtApp.runWithContext(() => getRouteRules({ path: to.path }));
148
- if (routeRules.appMiddleware) {
149
- for (const key in routeRules.appMiddleware) {
150
- if (routeRules.appMiddleware[key]) {
151
- middlewareEntries.add(key);
152
- } else {
153
- middlewareEntries.delete(key);
154
- }
145
+ const routeRules = getRouteRules({ path: to.path });
146
+ if (routeRules.appMiddleware) {
147
+ for (const key in routeRules.appMiddleware) {
148
+ if (routeRules.appMiddleware[key]) {
149
+ middlewareEntries.add(key);
150
+ } else {
151
+ middlewareEntries.delete(key);
155
152
  }
156
153
  }
157
154
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-nightly",
3
- "version": "4.3.0-29435873.41a564d2",
3
+ "version": "4.3.0-29436247.ecea7a86",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -67,11 +67,11 @@
67
67
  "@dxup/nuxt": "^0.3.2",
68
68
  "@nuxt/cli": "npm:@nuxt/cli-nightly@latest",
69
69
  "@nuxt/devtools": "^3.1.1",
70
- "@nuxt/kit": "npm:@nuxt/kit-nightly@4.3.0-29435873.41a564d2",
71
- "@nuxt/nitro-server": "npm:@nuxt/nitro-server-nightly@4.3.0-29435873.41a564d2",
72
- "@nuxt/schema": "npm:@nuxt/schema-nightly@4.3.0-29435873.41a564d2",
70
+ "@nuxt/kit": "npm:@nuxt/kit-nightly@4.3.0-29436247.ecea7a86",
71
+ "@nuxt/nitro-server": "npm:@nuxt/nitro-server-nightly@4.3.0-29436247.ecea7a86",
72
+ "@nuxt/schema": "npm:@nuxt/schema-nightly@4.3.0-29436247.ecea7a86",
73
73
  "@nuxt/telemetry": "^2.6.6",
74
- "@nuxt/vite-builder": "npm:@nuxt/vite-builder-nightly@4.3.0-29435873.41a564d2",
74
+ "@nuxt/vite-builder": "npm:@nuxt/vite-builder-nightly@4.3.0-29436247.ecea7a86",
75
75
  "@unhead/vue": "^2.0.19",
76
76
  "@vue/shared": "^3.5.25",
77
77
  "c12": "^3.3.2",
@@ -106,7 +106,7 @@
106
106
  "pathe": "^2.0.3",
107
107
  "perfect-debounce": "^2.0.0",
108
108
  "pkg-types": "^2.3.0",
109
- "radix3": "^1.1.2",
109
+ "rou3": "^0.7.12",
110
110
  "scule": "^1.3.0",
111
111
  "semver": "^7.7.3",
112
112
  "std-env": "^3.10.0",