nuxt-nightly 4.1.1-29283059.19187643 → 4.1.1-29283211.1cd8a685

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,9 +1,8 @@
1
1
  import { computed, getCurrentInstance, getCurrentScope, inject, isShallow, nextTick, onBeforeMount, onScopeDispose, onServerPrefetch, onUnmounted, ref, shallowRef, toRef, toValue, unref, watch } from "vue";
2
- import { captureStackTrace } from "errx";
3
2
  import { debounce } from "perfect-debounce";
4
3
  import { hash } from "ohash";
5
4
  import { useNuxtApp } from "../nuxt.js";
6
- import { toArray } from "../utils.js";
5
+ import { getUserCaller, toArray } from "../utils.js";
7
6
  import { clientOnlySymbol } from "../components/client-only.js";
8
7
  import { createError } from "./error.js";
9
8
  import { onNuxtReady } from "./ready.js";
@@ -49,9 +48,8 @@ export function useAsyncData(...args) {
49
48
  warnings.push(`mismatching \`deep\` option`);
50
49
  }
51
50
  if (warnings.length) {
52
- const distURL = import.meta.url.replace(/\/app\/.*$/, "/app");
53
- const { source, line, column } = captureStackTrace().find((entry) => !entry.source.startsWith(distURL)) ?? {};
54
- const explanation = source ? ` (used at ${source.replace(/^file:\/\//, "")}:${line}:${column})` : "";
51
+ const caller = getUserCaller();
52
+ const explanation = caller ? ` (used at ${caller.source}:${caller.line}:${caller.column})` : "";
55
53
  console.warn(`[nuxt] [${functionName}] Incompatible options detected for "${key.value}"${explanation}:
56
54
  ${warnings.map((w) => `- ${w}`).join("\n")}
57
55
  You can use a different key or move the call to a composable to ensure the options are shared across calls.`);
@@ -344,9 +342,8 @@ function createAsyncData(nuxtApp, key, _handler, options, initialCachedData) {
344
342
  result = pick(result, options.pick);
345
343
  }
346
344
  if (import.meta.dev && import.meta.server && typeof result === "undefined") {
347
- const stack = captureStackTrace();
348
- const { source, line, column } = stack[stack.length - 1] ?? {};
349
- const explanation = source ? ` (used at ${source.replace(/^file:\/\//, "")}:${line}:${column})` : "";
345
+ const caller = getUserCaller();
346
+ const explanation = caller ? ` (used at ${caller.source}:${caller.line}:${caller.column})` : "";
350
347
  console.warn(`[nuxt] \`${options._functionName || "useAsyncData"}${explanation}\` must return a value (it should not be \`undefined\`) or the request may be duplicated on the client side.`);
351
348
  }
352
349
  nuxtApp.payload.data[key] = result;
@@ -4,12 +4,15 @@ import { hasProtocol, isScriptProtocol, joinURL, parseQuery, parseURL, withQuery
4
4
  import { useNuxtApp, useRuntimeConfig } from "../nuxt.js";
5
5
  import { PageRouteSymbol } from "../components/injections.js";
6
6
  import { createError, showError } from "./error.js";
7
+ import { getUserTrace } from "../utils.js";
7
8
  export const useRouter = () => {
8
9
  return useNuxtApp()?.$router;
9
10
  };
10
11
  export const useRoute = () => {
11
12
  if (import.meta.dev && !getCurrentInstance() && isProcessingMiddleware()) {
12
- console.warn("[nuxt] Calling `useRoute` within middleware may lead to misleading results. Instead, use the (to, from) arguments passed to the middleware to access the new and old routes. Learn more: https://nuxt.com/docs/4.x/guide/directory-structure/app/middleware#accessing-route-in-middleware");
13
+ const middleware = useNuxtApp()._processingMiddleware;
14
+ const trace = getUserTrace().map(({ source, line, column }) => `at ${source}:${line}:${column}`).join("\n");
15
+ console.warn(`[nuxt] \`useRoute\` was called within middleware${typeof middleware === "string" ? ` (\`${middleware}\`)` : ""}. This may lead to misleading results. Instead, use the (to, from) arguments passed to the middleware to access the new and old routes. Learn more: https://nuxt.com/docs/4.x/guide/directory-structure/app/middleware#accessing-route-in-middleware` + ("\n" + trace));
13
16
  }
14
17
  if (hasInjectionContext()) {
15
18
  return inject(PageRouteSymbol, useNuxtApp()._route);
@@ -134,6 +134,8 @@ interface _NuxtApp {
134
134
  named: Record<string, RouteMiddleware>;
135
135
  };
136
136
  /** @internal */
137
+ _processingMiddleware?: string | boolean;
138
+ /** @internal */
137
139
  _once: {
138
140
  [key: string]: Promise<any>;
139
141
  };
@@ -178,6 +178,9 @@ export default defineNuxtPlugin({
178
178
  }
179
179
  }
180
180
  for (const middleware of middlewareEntries) {
181
+ if (import.meta.dev) {
182
+ nuxtApp._processingMiddleware = middleware.name || true;
183
+ }
181
184
  const result = await nuxtApp.runWithContext(() => middleware(to, from));
182
185
  if (import.meta.server) {
183
186
  if (result === false || result instanceof Error) {
@@ -1,2 +1,13 @@
1
1
  /** @since 3.9.0 */
2
2
  export declare function toArray<T>(value: T | T[]): T[];
3
+ export declare function getUserTrace(): {
4
+ source: string;
5
+ column?: number;
6
+ function?: string;
7
+ line?: number;
8
+ }[];
9
+ export declare function getUserCaller(): {
10
+ source: string;
11
+ line: number | undefined;
12
+ column: number | undefined;
13
+ } | null;
package/dist/app/utils.js CHANGED
@@ -1,3 +1,34 @@
1
+ import { captureStackTrace } from "errx";
1
2
  export function toArray(value) {
2
3
  return Array.isArray(value) ? value : [value];
3
4
  }
5
+ const distURL = import.meta.url.replace(/\/app\/.*$/, "/");
6
+ export function getUserTrace() {
7
+ if (!import.meta.dev) {
8
+ return [];
9
+ }
10
+ const trace = captureStackTrace();
11
+ const start = trace.findIndex((entry) => !entry.source.startsWith(distURL));
12
+ const end = [...trace].reverse().findIndex((entry) => !entry.source.includes("node_modules") && !entry.source.startsWith(distURL));
13
+ if (start === -1 || end === -1) {
14
+ return [];
15
+ }
16
+ return trace.slice(start, -end).map((i) => ({
17
+ ...i,
18
+ source: i.source.replace(/^file:\/\//, "")
19
+ }));
20
+ }
21
+ export function getUserCaller() {
22
+ if (!import.meta.dev) {
23
+ return null;
24
+ }
25
+ const { source, line, column } = captureStackTrace().find((entry) => !entry.source.startsWith(distURL)) ?? {};
26
+ if (!source) {
27
+ return null;
28
+ }
29
+ return {
30
+ source: source.replace(/^file:\/\//, ""),
31
+ line,
32
+ column
33
+ };
34
+ }
package/dist/index.mjs CHANGED
@@ -3760,7 +3760,7 @@ function addDeclarationTemplates(ctx, options) {
3760
3760
  });
3761
3761
  }
3762
3762
 
3763
- const version = "4.1.1-29283059.19187643";
3763
+ const version = "4.1.1-29283211.1cd8a685";
3764
3764
 
3765
3765
  const createImportProtectionPatterns = (nuxt, options) => {
3766
3766
  const patterns = [];
@@ -165,6 +165,9 @@ const plugin = defineNuxtPlugin({
165
165
  throw new Error(`Unknown route middleware: '${entry}'.`);
166
166
  }
167
167
  try {
168
+ if (import.meta.dev) {
169
+ nuxtApp._processingMiddleware = (typeof entry === "string" ? entry : middleware.name) || true;
170
+ }
168
171
  const result = await nuxtApp.runWithContext(() => middleware(to, from));
169
172
  if (import.meta.server || !nuxtApp.payload.serverRendered && nuxtApp.isHydrating) {
170
173
  if (result === false || result instanceof Error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nuxt-nightly",
3
- "version": "4.1.1-29283059.19187643",
3
+ "version": "4.1.1-29283211.1cd8a685",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/nuxt/nuxt.git",
@@ -67,10 +67,10 @@
67
67
  "@nuxt/cli": "npm:@nuxt/cli-nightly@latest",
68
68
  "@nuxt/devalue": "^2.0.2",
69
69
  "@nuxt/devtools": "^2.6.3",
70
- "@nuxt/kit": "npm:@nuxt/kit-nightly@4.1.1-29283059.19187643",
71
- "@nuxt/schema": "npm:@nuxt/schema-nightly@4.1.1-29283059.19187643",
70
+ "@nuxt/kit": "npm:@nuxt/kit-nightly@4.1.1-29283211.1cd8a685",
71
+ "@nuxt/schema": "npm:@nuxt/schema-nightly@4.1.1-29283211.1cd8a685",
72
72
  "@nuxt/telemetry": "^2.6.6",
73
- "@nuxt/vite-builder": "npm:@nuxt/vite-builder-nightly@4.1.1-29283059.19187643",
73
+ "@nuxt/vite-builder": "npm:@nuxt/vite-builder-nightly@4.1.1-29283211.1cd8a685",
74
74
  "@unhead/vue": "^2.0.14",
75
75
  "@vue/shared": "^3.5.20",
76
76
  "c12": "^3.2.0",