vike-lite 1.15.14 → 1.15.15

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,7 +1,10 @@
1
+ import { t as VikeState } from "../store-9UNcAe5D.mjs";
1
2
  //#region src/__internal/client.d.ts
2
3
  declare function createLinkClickHandler(onNavigate: (url: URL) => void): (e: MouseEvent) => void;
3
4
  declare function createLinkPrefetchHandler(onPrefetch: (url: URL) => void): (e: Event) => void;
4
- declare function finalizeNavigation(scrollStateSetState: boolean): void;
5
+ declare function finalizeNavigation(shouldScrollToTop: {
6
+ current: boolean;
7
+ }): void;
5
8
  interface ViewComponents {
6
9
  Page: any | null;
7
10
  Layout: any | null;
@@ -49,5 +52,37 @@ declare function createRoutePrefetcher(): (route: PrefetchableRoute) => void;
49
52
  * Returns true if a reload was triggered — the caller should stop further error handling.
50
53
  */
51
54
  declare function tryRecoverFromStaleModuleGraph(message: string, urlToReload: string): boolean;
55
+ /**
56
+ * Stamp the client-only flags that every `PageContextClient` requires (`isClientSide`,
57
+ * `isHydration`) onto the raw context blob the server injected via `window.__PAGE_CONTEXT__`.
58
+ * Centralized so every adapter sets these consistently instead of some silently omitting them.
59
+ */
60
+ declare function buildInitialClientContext<T extends Record<string, any>>(rawContext: T | undefined, isHydration: boolean): T & {
61
+ isClientSide: true;
62
+ isHydration: boolean;
63
+ };
64
+ interface HydrationInitialContext {
65
+ urlPathname?: string;
66
+ is404?: boolean;
67
+ is500?: boolean;
68
+ errorMessage?: string;
69
+ }
70
+ /**
71
+ * Resolve the Page/Layout/Head modules to hydrate with, matching what the server
72
+ * actually rendered into the HTML: the error route's modules when the server
73
+ * reported a 404/500/error, otherwise the modules of the route matching the
74
+ * initial pathname. Returns a null view when hydration isn't happening (client
75
+ * takeover) — the router's own first-load effect performs the initial load instead.
76
+ */
77
+ declare function resolveHydrationView(initialContext: HydrationInitialContext, isHydration: boolean, routes: VikeState['routes'], errorRoute: VikeState['errorRoute']): Promise<ViewComponents>;
78
+ /**
79
+ * Consume the server-injected initial context if it still matches the given pathname
80
+ * (i.e. this is the very first client-side route load, right after SSR hydration/render).
81
+ * Clears the global reference so a later remount at the same pathname (e.g. React
82
+ * StrictMode double-invoke in dev) triggers a real fetch instead of being mistaken
83
+ * for the original initial load. Returns true if consumed — the caller should skip
84
+ * loading for this run.
85
+ */
86
+ declare function consumeMatchingInitialContext(pathname: string): boolean;
52
87
  //#endregion
53
- export { ViewComponents, buildPageContextJsonUrl, createLinkClickHandler, createLinkPrefetchHandler, createRoutePrefetcher, fetchPageContextJson, finalizeNavigation, loadViewModules, tryRecoverFromStaleModuleGraph };
88
+ export { ViewComponents, buildInitialClientContext, buildPageContextJsonUrl, consumeMatchingInitialContext, createLinkClickHandler, createLinkPrefetchHandler, createRoutePrefetcher, fetchPageContextJson, finalizeNavigation, loadViewModules, resolveHydrationView, tryRecoverFromStaleModuleGraph };
@@ -1,4 +1,4 @@
1
- import { BASE_URL } from "./shared.mjs";
1
+ import { BASE_URL, matchRoute } from "./shared.mjs";
2
2
  //#region src/__internal/client.ts
3
3
  function getClientSideUrl(target) {
4
4
  if (!target?.href || target.target && target.target !== "_self" || target.hasAttribute("download") || target.hasAttribute("data-native") || target.getAttribute("rel")?.includes("external")) return null;
@@ -15,7 +15,7 @@ function isSamePage(url) {
15
15
  }
16
16
  function createLinkClickHandler(onNavigate) {
17
17
  return (e) => {
18
- if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey) return;
18
+ if (e.defaultPrevented || e.button !== 0 || e.metaKey || e.ctrlKey || e.shiftKey || e.altKey || !(e.target instanceof Element)) return;
19
19
  const url = getClientSideUrl(e.target.closest("a"));
20
20
  if (!url || isSamePage(url)) return;
21
21
  e.preventDefault();
@@ -25,15 +25,16 @@ function createLinkClickHandler(onNavigate) {
25
25
  }
26
26
  function createLinkPrefetchHandler(onPrefetch) {
27
27
  return (e) => {
28
+ if (!(e.target instanceof Element)) return;
28
29
  const url = getClientSideUrl(e.target.closest("a"));
29
30
  if (!url || isSamePage(url)) return;
30
31
  onPrefetch(url);
31
32
  };
32
33
  }
33
- function finalizeNavigation(scrollStateSetState) {
34
- if (scrollStateSetState) {
34
+ function finalizeNavigation(shouldScrollToTop) {
35
+ if (shouldScrollToTop.current) {
35
36
  globalThis.scrollTo(0, 0);
36
- scrollStateSetState = false;
37
+ shouldScrollToTop.current = false;
37
38
  } else if (globalThis.location.hash) requestAnimationFrame(() => {
38
39
  try {
39
40
  document.querySelector(decodeURIComponent(globalThis.location.hash))?.scrollIntoView();
@@ -111,5 +112,48 @@ function tryRecoverFromStaleModuleGraph(message, urlToReload) {
111
112
  globalThis.location.assign(urlToReload);
112
113
  return true;
113
114
  }
115
+ /**
116
+ * Stamp the client-only flags that every `PageContextClient` requires (`isClientSide`,
117
+ * `isHydration`) onto the raw context blob the server injected via `window.__PAGE_CONTEXT__`.
118
+ * Centralized so every adapter sets these consistently instead of some silently omitting them.
119
+ */
120
+ function buildInitialClientContext(rawContext, isHydration) {
121
+ return {
122
+ ...rawContext ?? {},
123
+ isClientSide: true,
124
+ isHydration
125
+ };
126
+ }
127
+ /**
128
+ * Resolve the Page/Layout/Head modules to hydrate with, matching what the server
129
+ * actually rendered into the HTML: the error route's modules when the server
130
+ * reported a 404/500/error, otherwise the modules of the route matching the
131
+ * initial pathname. Returns a null view when hydration isn't happening (client
132
+ * takeover) — the router's own first-load effect performs the initial load instead.
133
+ */
134
+ async function resolveHydrationView(initialContext, isHydration, routes, errorRoute) {
135
+ const emptyView = {
136
+ Page: null,
137
+ Layout: null,
138
+ Head: null
139
+ };
140
+ if (!isHydration) return emptyView;
141
+ if ((initialContext.is404 || initialContext.is500 || initialContext.errorMessage) && errorRoute) return loadViewModules(errorRoute);
142
+ const matched = matchRoute(initialContext.urlPathname ?? globalThis.location.pathname, routes);
143
+ return matched ? loadViewModules(matched.route) : emptyView;
144
+ }
145
+ /**
146
+ * Consume the server-injected initial context if it still matches the given pathname
147
+ * (i.e. this is the very first client-side route load, right after SSR hydration/render).
148
+ * Clears the global reference so a later remount at the same pathname (e.g. React
149
+ * StrictMode double-invoke in dev) triggers a real fetch instead of being mistaken
150
+ * for the original initial load. Returns true if consumed — the caller should skip
151
+ * loading for this run.
152
+ */
153
+ function consumeMatchingInitialContext(pathname) {
154
+ if (globalThis.__PAGE_CONTEXT__?.urlPathname !== pathname) return false;
155
+ globalThis.__PAGE_CONTEXT__ = void 0;
156
+ return true;
157
+ }
114
158
  //#endregion
115
- export { buildPageContextJsonUrl, createLinkClickHandler, createLinkPrefetchHandler, createRoutePrefetcher, fetchPageContextJson, finalizeNavigation, loadViewModules, tryRecoverFromStaleModuleGraph };
159
+ export { buildInitialClientContext, buildPageContextJsonUrl, consumeMatchingInitialContext, createLinkClickHandler, createLinkPrefetchHandler, createRoutePrefetcher, fetchPageContextJson, finalizeNavigation, loadViewModules, resolveHydrationView, tryRecoverFromStaleModuleGraph };
@@ -1,11 +1,2 @@
1
- //#region src/server/store.d.ts
2
- interface VikeState {
3
- routes: typeof import('virtual:vike-lite/routes')['routes'] | [];
4
- errorRoute: typeof import('virtual:vike-lite/routes')['errorRoute'] | null;
5
- config: typeof import('virtual:vike-lite/routes')['config'] | null;
6
- manifest: typeof import('virtual:vike-lite/client-manifest')['default'] | null;
7
- }
8
- declare const store: VikeState;
9
- declare function setVikeState(newState: Partial<VikeState>): void;
10
- //#endregion
1
+ import { n as setVikeState, r as store, t as VikeState } from "../store-9UNcAe5D.mjs";
11
2
  export { VikeState, setVikeState, store };
@@ -0,0 +1,11 @@
1
+ //#region src/server/store.d.ts
2
+ interface VikeState {
3
+ routes: typeof import('virtual:vike-lite/routes')['routes'] | [];
4
+ errorRoute: typeof import('virtual:vike-lite/routes')['errorRoute'] | null;
5
+ config: typeof import('virtual:vike-lite/routes')['config'] | null;
6
+ manifest: typeof import('virtual:vike-lite/client-manifest')['default'] | null;
7
+ }
8
+ declare const store: VikeState;
9
+ declare function setVikeState(newState: Partial<VikeState>): void;
10
+ //#endregion
11
+ export { setVikeState as n, store as r, VikeState as t };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vike-lite",
3
- "version": "1.15.14",
3
+ "version": "1.15.15",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",