inertiax-svelte 11.0.21 → 11.0.23

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.
@@ -11,6 +11,8 @@
11
11
  resolveComponent: ComponentResolver
12
12
  defaultLayout?: (name: string, page: Page) => unknown
13
13
  renderLayout?: boolean
14
+ /** When `true`, always makes an HTTP request on mount even if page data exists in the history stack. Defaults to `false`. */
15
+ skipHistoryRestore?: boolean
14
16
  /** Visit options applied to all navigations within this frame. Link/form-level options take precedence. Non-top frames default to `{ replace: true, updateBrowserUrl: false }`, top frame defaults to `{ replace: false, updateBrowserUrl: true }`. */
15
17
  visitOptions?: import('inertiax-core').VisitOptions
16
18
  /** Called when a plain <a> inside the frame is clicked. Call event.preventDefault() to prevent the default Inertia navigation. */
@@ -41,6 +43,7 @@
41
43
  resolveComponent?: InertiaFrameProps['resolveComponent']
42
44
  defaultLayout?: InertiaFrameProps['defaultLayout']
43
45
  renderLayout?: InertiaFrameProps['renderLayout']
46
+ skipHistoryRestore?: InertiaFrameProps['skipHistoryRestore']
44
47
  visitOptions?: InertiaFrameProps['visitOptions']
45
48
  onClickLink?: InertiaFrameProps['onClickLink']
46
49
  children?: InertiaFrameProps['children']
@@ -55,6 +58,7 @@
55
58
  resolveComponent = undefined,
56
59
  defaultLayout,
57
60
  renderLayout = undefined,
61
+ skipHistoryRestore = false,
58
62
  visitOptions,
59
63
  onClickLink,
60
64
  children,
@@ -73,9 +77,10 @@
73
77
  return `frame-${Math.random().toString(36).slice(2, 10)}`
74
78
  }
75
79
 
76
- // App passes DEFAULT_FRAME_ID explicitly for the top frame. All other
77
- // implicit frames get an isolated generated id.
78
- const frameId = id ?? createFrameId()
80
+ // Use explicit id > src > random UUID. Using src as the frameId gives
81
+ // frames a deterministic identity remounts with the same src share
82
+ // history state, so the history-restore optimisation works naturally.
83
+ const frameId = id ?? src ?? createFrameId()
79
84
  const shouldRenderLayout = renderLayout ?? frameId === DEFAULT_FRAME_ID
80
85
 
81
86
  function resolveFrameComponent(name: string, page?: Page) {
@@ -191,6 +196,22 @@
191
196
  }
192
197
 
193
198
  const load = async () => {
199
+ // Try to restore from history state first — avoids an unnecessary
200
+ // request when the frame's page data is already in the history stack.
201
+ if (!skipHistoryRestore) {
202
+ try {
203
+ const historyPage = await frameRouter.decryptHistory()
204
+
205
+ if (historyPage && historyPage.component) {
206
+ initRouter(historyPage)
207
+
208
+ return
209
+ }
210
+ } catch {
211
+ // No history state available, fall through to HTTP request.
212
+ }
213
+ }
214
+
194
215
  const version = page?.version ?? globalPage.version ?? (window as any)?.initialPage?.version ?? null
195
216
 
196
217
  const response = await http.getClient().request({
@@ -9,6 +9,7 @@ export interface InertiaFrameProps<SharedProps extends PageProps = PageProps> {
9
9
  resolveComponent: ComponentResolver;
10
10
  defaultLayout?: (name: string, page: Page) => unknown;
11
11
  renderLayout?: boolean;
12
+ skipHistoryRestore?: boolean;
12
13
  visitOptions?: import('inertiax-core').VisitOptions;
13
14
  onClickLink?: (event: MouseEvent, href: string) => void;
14
15
  children?: import('svelte').Snippet;
@@ -24,6 +25,7 @@ interface Props {
24
25
  resolveComponent?: InertiaFrameProps['resolveComponent'];
25
26
  defaultLayout?: InertiaFrameProps['defaultLayout'];
26
27
  renderLayout?: InertiaFrameProps['renderLayout'];
28
+ skipHistoryRestore?: InertiaFrameProps['skipHistoryRestore'];
27
29
  visitOptions?: InertiaFrameProps['visitOptions'];
28
30
  onClickLink?: InertiaFrameProps['onClickLink'];
29
31
  children?: InertiaFrameProps['children'];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inertiax-svelte",
3
- "version": "11.0.21",
3
+ "version": "11.0.23",
4
4
  "license": "MIT",
5
5
  "description": "The Svelte adapter for Inertia.js",
6
6
  "contributors": [
@@ -55,7 +55,7 @@
55
55
  "dependencies": {
56
56
  "es-toolkit": "^1.47.1",
57
57
  "laravel-precognition": "^2.0.0",
58
- "inertiax-core": "11.0.21"
58
+ "inertiax-core": "11.0.23"
59
59
  },
60
60
  "scripts": {
61
61
  "build": "pnpm package && svelte-check --tsconfig ./tsconfig.json && publint",
package/readme.md CHANGED
@@ -11,7 +11,7 @@ Each frame manages its own router, history, and component tree.
11
11
 
12
12
  | Prop | Type | Default | Description |
13
13
  |------|------|---------|-------------|
14
- | `id` | `string` | auto-generated | Frame identifier. Use `"_top"` for the root frame. |
14
+ | `id` | `string` | `src` value, then auto-generated | Frame identifier. Deterministic when derived from `src`. |
15
15
  | `src` | `string` | — | URL to load the frame content from. |
16
16
  | `router` | `Router` | auto-created | Custom router instance. |
17
17
  | `initialComponent` | `ResolvedComponent` | — | Pre-resolved component for SSR/hydration. |
@@ -21,6 +21,7 @@ Each frame manages its own router, history, and component tree.
21
21
  | `renderLayout` | `boolean` | `true` for top frame | Whether to wrap content in layouts. |
22
22
  | `visitOptions` | `VisitOptions` | `{ replace: true, updateBrowserUrl: false }` (non-top) / `{ replace: false, updateBrowserUrl: true }` (top) | Default visit options applied to all navigations within the frame. Link/form-level options take precedence. |
23
23
  | `onClickLink` | `(event, href) => void` | — | Called when a plain `<a>` inside the frame is clicked. Call `event.preventDefault()` to prevent navigation. |
24
+ | `skipHistoryRestore` | `boolean` | `false` | When `true`, always makes an HTTP request on mount instead of restoring from history. |
24
25
  | `children` | `Snippet` | — | Fallback content rendered while the frame loads. |
25
26
 
26
27
  ### Scroll regions