@adonisjs/inertia 4.2.0 → 5.0.0-next.1

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.
Files changed (39) hide show
  1. package/build/commands/make_page.js +15 -0
  2. package/build/debug-Ca0ekg3M.js +25 -0
  3. package/build/factories/inertia_factory.d.ts +25 -0
  4. package/build/factories/main.js +144 -5
  5. package/build/headers-B-5pLwyD.js +77 -0
  6. package/build/index.js +3 -4
  7. package/build/inertia-ZqLiRJME.js +141 -0
  8. package/build/inertia_manager-BeqpMsuN.js +1770 -0
  9. package/build/providers/inertia_provider.js +69 -3
  10. package/build/src/client/helpers.js +28 -0
  11. package/build/src/client/react/context.d.ts +1 -1
  12. package/build/src/client/react/form.d.ts +1 -1
  13. package/build/src/client/react/index.js +144 -1
  14. package/build/src/client/react/link.d.ts +1 -1
  15. package/build/src/client/vue/index.js +95 -1
  16. package/build/src/define_config.d.ts +1 -1
  17. package/build/src/headers.d.ts +13 -0
  18. package/build/src/inertia.d.ts +58 -2
  19. package/build/src/inertia_middleware.d.ts +37 -1
  20. package/build/src/inertia_middleware.js +72 -5
  21. package/build/src/plugins/edge/plugin.js +124 -4
  22. package/build/src/plugins/japa/api_client.js +50 -1
  23. package/build/src/props.d.ts +118 -28
  24. package/build/src/server_renderer.d.ts +4 -28
  25. package/build/src/symbols.d.ts +33 -0
  26. package/build/src/types.d.ts +405 -15
  27. package/build/tests/helpers.d.ts +52 -0
  28. package/build/tests/merges.spec.d.ts +1 -0
  29. package/build/tests/once_props.spec.d.ts +1 -0
  30. package/build/tests/rescued_deferred_props.spec.d.ts +1 -0
  31. package/build/tests/scroll.spec.d.ts +1 -0
  32. package/build/tests/v3_client_contract.spec.d.ts +1 -0
  33. package/package.json +31 -30
  34. package/build/debug-CBMTuPUm.js +0 -3
  35. package/build/define_config-Du2hAFGX.js +0 -57
  36. package/build/headers-DafWEpBh.js +0 -11
  37. package/build/inertia_manager-BGHA4cDP.js +0 -418
  38. package/build/src/client/vite.d.ts +0 -65
  39. package/build/src/client/vite.js +0 -21
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@adonisjs/inertia",
3
3
  "description": "Official Inertia.js adapter for AdonisJS",
4
- "version": "4.2.0",
4
+ "version": "5.0.0-next.1",
5
5
  "engines": {
6
6
  "node": ">=24.0.0"
7
7
  },
@@ -17,7 +17,6 @@
17
17
  "./inertia_provider": "./build/providers/inertia_provider.js",
18
18
  "./plugins/edge": "./build/src/plugins/edge/plugin.js",
19
19
  "./plugins/api_client": "./build/src/plugins/japa/api_client.js",
20
- "./vite": "./build/src/client/vite.js",
21
20
  "./helpers": "./build/src/client/helpers.js",
22
21
  "./react": "./build/src/client/react/index.js",
23
22
  "./vue": "./build/src/client/vue/index.js",
@@ -41,51 +40,53 @@
41
40
  "format": "prettier --write .",
42
41
  "prepublishOnly": "npm run build",
43
42
  "lint": "eslint",
43
+ "lint:ast": "ast-grep scan",
44
44
  "index:commands": "adonis-kit index build/commands",
45
45
  "quick:test": "cross-env NODE_DEBUG=adonisjs:inertia node --import=@poppinss/ts-exec --enable-source-maps bin/test.ts",
46
46
  "docs": "typedoc"
47
47
  },
48
48
  "devDependencies": {
49
- "@adonisjs/assembler": "^8.0.0",
50
- "@adonisjs/core": "^7.0.0",
51
- "@adonisjs/eslint-config": "^3.0.0",
52
- "@adonisjs/prettier-config": "^1.4.5",
53
- "@adonisjs/session": "^8.0.0",
49
+ "@adonisjs/assembler": "^8.4.0",
50
+ "@adonisjs/core": "^7.3.5",
51
+ "@adonisjs/eslint-config": "^3.1.0",
52
+ "@adonisjs/prettier-config": "^1.5.0",
53
+ "@adonisjs/session": "^8.1.0",
54
54
  "@adonisjs/tsconfig": "^2.0.0",
55
- "@adonisjs/vite": "^5.1.0",
56
- "@inertiajs/react": "^2.3.16",
57
- "@inertiajs/vue3": "^2.3.16",
55
+ "@adonisjs/vite": "^6.0.0-next.1",
56
+ "@ast-grep/cli": "^0.44.1",
57
+ "@inertiajs/react": "^3.6.1",
58
+ "@inertiajs/vue3": "^3.6.1",
58
59
  "@japa/api-client": "^3.2.1",
59
60
  "@japa/assert": "4.2.0",
60
61
  "@japa/expect-type": "^2.0.4",
61
62
  "@japa/file-system": "^3.0.0",
62
- "@japa/plugin-adonisjs": "^5.1.0",
63
+ "@japa/plugin-adonisjs": "^5.2.0",
63
64
  "@japa/runner": "5.3.0",
64
65
  "@japa/snapshot": "^2.0.10",
65
66
  "@poppinss/ts-exec": "^1.4.4",
66
- "@release-it/conventional-changelog": "^10.0.5",
67
- "@tuyau/core": "^1.0.0",
68
- "@types/node": "^25.3.0",
69
- "@types/react": "^19.2.14",
70
- "@types/supertest": "^6.0.3",
67
+ "@release-it/conventional-changelog": "^11.0.1",
68
+ "@tuyau/core": "^1.2.2",
69
+ "@types/node": "^26.1.1",
70
+ "@types/react": "^19.2.17",
71
+ "@types/supertest": "^7.2.1",
71
72
  "c8": "^11.0.0",
72
73
  "copyfiles": "^2.4.1",
73
74
  "cross-env": "^10.1.0",
74
75
  "del-cli": "^7.0.0",
75
- "edge.js": "^6.5.0",
76
- "eslint": "^10.0.2",
77
- "get-port": "^7.1.0",
78
- "prettier": "^3.8.1",
79
- "react": "^19.2.4",
80
- "release-it": "^19.2.4",
76
+ "edge.js": "^6.5.1",
77
+ "eslint": "^10.7.0",
78
+ "get-port": "^7.2.0",
79
+ "prettier": "^3.9.5",
80
+ "react": "^19.2.7",
81
+ "release-it": "^20.2.1",
81
82
  "supertest": "^7.2.2",
82
- "tsdown": "^0.20.3",
83
- "typescript": "~5.9.3",
84
- "vite": "^7.3.1",
85
- "vue": "^3.5.29"
83
+ "tsdown": "^0.22.7",
84
+ "typescript": "~6.0.3",
85
+ "vite": "^8.1.4",
86
+ "vue": "^3.5.39"
86
87
  },
87
88
  "dependencies": {
88
- "@poppinss/utils": "^7.0.0",
89
+ "@poppinss/utils": "^7.0.1",
89
90
  "edge-error": "^4.0.2",
90
91
  "html-entities": "^2.6.0"
91
92
  },
@@ -93,9 +94,9 @@
93
94
  "@adonisjs/assembler": "^8.0.0-next.29 || ^8.0.0",
94
95
  "@adonisjs/core": "^7.0.0-next.23 || ^7.0.0",
95
96
  "@adonisjs/session": "^8.0.0-next.2 || ^8.0.0",
96
- "@adonisjs/vite": "^5.1.0-next.2 || ^5.1.0",
97
- "@inertiajs/react": "^2.3.8",
98
- "@inertiajs/vue3": "^2.3.8",
97
+ "@adonisjs/vite": "^6.0.0-next.0 || ^6.0.0",
98
+ "@inertiajs/react": "^3.4.0",
99
+ "@inertiajs/vue3": "^3.4.0",
99
100
  "@japa/api-client": "^3.1.1",
100
101
  "@japa/plugin-adonisjs": "^5.1.0-next.1 || ^5.1.0",
101
102
  "@tuyau/core": "^1.0.0-beta.10 || ^1.0.0",
@@ -1,3 +0,0 @@
1
- import { debuglog } from "node:util";
2
- var debug_default = debuglog("adonisjs:inertia");
3
- export { debug_default as t };
@@ -1,57 +0,0 @@
1
- import lodash from "@poppinss/utils/lodash";
2
- const GLOB = {
3
- vue3: ["**/*.vue"],
4
- react: ["**/*.ts", "**/*.tsx"]
5
- };
6
- const SUPPORTED_FRAMEWORKS = Object.keys(GLOB);
7
- const TYPES_EXTRACTION_HELPER = {
8
- vue3: `import type { VNodeProps, AllowedComponentProps, ComponentInstance } from 'vue'
9
-
10
- type ExtractProps<T> = Omit<
11
- ComponentInstance<T>['$props'],
12
- keyof VNodeProps | keyof AllowedComponentProps
13
- >`,
14
- react: `import type React from 'react'
15
- import type { Prettify } from '@adonisjs/core/types/common'
16
-
17
- type ExtractProps<T> =
18
- T extends React.FC<infer Props>
19
- ? Prettify<Omit<Props, 'children'>>
20
- : T extends React.Component<infer Props>
21
- ? Prettify<Omit<Props, 'children'>>
22
- : never`
23
- };
24
- const indexPages = function(config) {
25
- if (!SUPPORTED_FRAMEWORKS.includes(config.framework)) throw new Error(`Unsupported framework "${config.framework}". Types generation is available only for ${SUPPORTED_FRAMEWORKS.join(",")}`);
26
- return { run(_, __, indexGenerator) {
27
- indexGenerator.add("inertiaPages", {
28
- source: config.source ?? "inertia/pages",
29
- glob: GLOB[config.framework],
30
- output: ".adonisjs/server/pages.d.ts",
31
- as(vfs, buffer, ___, helpers) {
32
- const filesList = vfs.asList();
33
- buffer.writeLine(`import '@adonisjs/inertia/types'`);
34
- buffer.writeLine(TYPES_EXTRACTION_HELPER[config.framework]);
35
- buffer.write(`declare module '@adonisjs/inertia/types' {`).indent();
36
- buffer.write(`export interface InertiaPages {`).indent();
37
- Object.keys(filesList).forEach((key) => {
38
- buffer.write(`'${key}': ExtractProps<(typeof import('${helpers.toImportPath(filesList[key])}'))['default']>`);
39
- });
40
- buffer.dedent().write(`}`);
41
- buffer.dedent().write(`}`);
42
- }
43
- });
44
- } };
45
- };
46
- function defineConfig(config) {
47
- return lodash.merge({
48
- rootView: "inertia_layout",
49
- history: { encrypt: false },
50
- ssr: {
51
- enabled: false,
52
- bundle: "ssr/ssr.js",
53
- entrypoint: "inertia/ssr.tsx"
54
- }
55
- }, config);
56
- }
57
- export { indexPages as n, defineConfig as t };
@@ -1,11 +0,0 @@
1
- const InertiaHeaders = {
2
- Inertia: "x-inertia",
3
- Reset: "x-inertia-reset",
4
- Version: "x-inertia-version",
5
- Location: "x-inertia-location",
6
- ErrorBag: "x-inertia-error-bag",
7
- PartialOnly: "x-inertia-partial-data",
8
- PartialExcept: "x-inertia-partial-except",
9
- PartialComponent: "x-inertia-partial-component"
10
- };
11
- export { InertiaHeaders as t };
@@ -1,418 +0,0 @@
1
- import { t as InertiaHeaders } from "./headers-DafWEpBh.js";
2
- import { t as debug_default } from "./debug-CBMTuPUm.js";
3
- import "node:module";
4
- import { createHash } from "node:crypto";
5
- import { BaseSerializer } from "@adonisjs/core/transformers";
6
- import { pathToFileURL } from "node:url";
7
- var __defProp = Object.defineProperty;
8
- var __exportAll = (all, no_symbols) => {
9
- let target = {};
10
- for (var name in all) __defProp(target, name, {
11
- get: all[name],
12
- enumerable: true
13
- });
14
- if (!no_symbols) __defProp(target, Symbol.toStringTag, { value: "Module" });
15
- return target;
16
- };
17
- var symbols_exports = /* @__PURE__ */ __exportAll({
18
- ALWAYS_PROP: () => ALWAYS_PROP,
19
- DEEP_MERGE: () => DEEP_MERGE,
20
- DEFERRED_PROP: () => DEFERRED_PROP,
21
- OPTIONAL_PROP: () => OPTIONAL_PROP,
22
- TO_BE_MERGED: () => TO_BE_MERGED
23
- });
24
- const ALWAYS_PROP = Symbol.for("ALWAYS_PROP");
25
- const OPTIONAL_PROP = Symbol.for("OPTIONAL_PROP");
26
- const TO_BE_MERGED = Symbol.for("TO_BE_MERGED");
27
- const DEFERRED_PROP = Symbol.for("DEFERRED_PROP");
28
- const DEEP_MERGE = Symbol.for("DEEP_MERGE");
29
- var InertiaSerializer = class extends BaseSerializer {
30
- wrap = void 0;
31
- definePaginationMetaData(metaData) {
32
- return metaData;
33
- }
34
- };
35
- const inertiaSerializer = new InertiaSerializer();
36
- function isObject(value) {
37
- return value !== null && typeof value === "object" && !Array.isArray(value);
38
- }
39
- function defer(fn, group = "default") {
40
- return {
41
- group,
42
- compute: fn,
43
- merge() {
44
- return merge(this);
45
- },
46
- [DEFERRED_PROP]: true
47
- };
48
- }
49
- function optional(fn) {
50
- return {
51
- compute: fn,
52
- [OPTIONAL_PROP]: true
53
- };
54
- }
55
- function always(value) {
56
- return {
57
- value,
58
- [ALWAYS_PROP]: true
59
- };
60
- }
61
- function merge(value) {
62
- return {
63
- value,
64
- [TO_BE_MERGED]: true,
65
- [DEEP_MERGE]: false
66
- };
67
- }
68
- function deepMerge(value) {
69
- return {
70
- value,
71
- [TO_BE_MERGED]: true,
72
- [DEEP_MERGE]: true
73
- };
74
- }
75
- function isDeferredProp(propValue) {
76
- return DEFERRED_PROP in propValue;
77
- }
78
- function isMergeableProp(propValue) {
79
- return TO_BE_MERGED in propValue;
80
- }
81
- function isAlwaysProp(propValue) {
82
- return ALWAYS_PROP in propValue;
83
- }
84
- function isOptionalProp(propValue) {
85
- return OPTIONAL_PROP in propValue;
86
- }
87
- async function unpackPropValue(value, containerResolver) {
88
- return inertiaSerializer.serialize(value, containerResolver);
89
- }
90
- async function buildStandardVisitProps(pageProps, containerResolver) {
91
- const mergeProps = [];
92
- const deepMergeProps = [];
93
- const newProps = {};
94
- const deferredProps = {};
95
- const unpackedValues = [];
96
- for (const [key, value] of Object.entries(pageProps)) if (isObject(value)) {
97
- if (isDeferredProp(value)) {
98
- deferredProps[value.group] = deferredProps[value.group] ?? [];
99
- deferredProps[value.group].push(key);
100
- continue;
101
- }
102
- if (isOptionalProp(value)) continue;
103
- if (isAlwaysProp(value)) {
104
- unpackedValues.push({
105
- key,
106
- value: value.value
107
- });
108
- continue;
109
- }
110
- if (isMergeableProp(value)) {
111
- if (value[DEEP_MERGE]) deepMergeProps.push(key);
112
- else mergeProps.push(key);
113
- if (isObject(value.value) && isDeferredProp(value.value)) {
114
- deferredProps[value.value.group] = deferredProps[value.value.group] ?? [];
115
- deferredProps[value.value.group].push(key);
116
- unpackedValues.push({
117
- key,
118
- value: value.value.compute
119
- });
120
- } else unpackedValues.push({
121
- key,
122
- value: value.value
123
- });
124
- continue;
125
- }
126
- unpackedValues.push({
127
- key,
128
- value
129
- });
130
- } else {
131
- if (typeof value === "function") {
132
- unpackedValues.push({
133
- key,
134
- value
135
- });
136
- continue;
137
- }
138
- newProps[key] = value;
139
- }
140
- await Promise.all(unpackedValues.map(async ({ key, value }) => {
141
- if (typeof value === "function") return Promise.resolve(value()).then((r) => unpackPropValue(r, containerResolver)).then((jsonValue) => {
142
- newProps[key] = jsonValue;
143
- });
144
- else return unpackPropValue(value, containerResolver).then((jsonValue) => {
145
- newProps[key] = jsonValue;
146
- });
147
- }));
148
- return {
149
- props: newProps,
150
- mergeProps,
151
- deepMergeProps,
152
- deferredProps
153
- };
154
- }
155
- async function buildPartialRequestProps(pageProps, cherryPickProps, containerResolver) {
156
- const mergeProps = [];
157
- const deepMergeProps = [];
158
- const newProps = {};
159
- const unpackedValues = [];
160
- for (const [key, value] of Object.entries(pageProps)) if (isObject(value)) {
161
- if (isAlwaysProp(value)) {
162
- unpackedValues.push({
163
- key,
164
- value: value.value
165
- });
166
- continue;
167
- }
168
- if (!cherryPickProps.includes(key)) continue;
169
- if (isDeferredProp(value)) {
170
- unpackedValues.push({
171
- key,
172
- value: value.compute
173
- });
174
- continue;
175
- }
176
- if (isOptionalProp(value)) {
177
- unpackedValues.push({
178
- key,
179
- value: value.compute
180
- });
181
- continue;
182
- }
183
- if (isMergeableProp(value)) {
184
- if (value[DEEP_MERGE]) deepMergeProps.push(key);
185
- else mergeProps.push(key);
186
- if (isObject(value.value) && isDeferredProp(value.value)) unpackedValues.push({
187
- key,
188
- value: value.value.compute
189
- });
190
- else unpackedValues.push({
191
- key,
192
- value: value.value
193
- });
194
- continue;
195
- }
196
- unpackedValues.push({
197
- key,
198
- value
199
- });
200
- } else {
201
- if (!cherryPickProps.includes(key)) continue;
202
- if (typeof value === "function") {
203
- unpackedValues.push({
204
- key,
205
- value
206
- });
207
- continue;
208
- }
209
- newProps[key] = value;
210
- }
211
- await Promise.all(unpackedValues.map(async ({ key, value }) => {
212
- if (typeof value === "function") return Promise.resolve(value()).then((r) => unpackPropValue(r, containerResolver)).then((jsonValue) => {
213
- newProps[key] = jsonValue;
214
- });
215
- else return unpackPropValue(value, containerResolver).then((jsonValue) => {
216
- newProps[key] = jsonValue;
217
- });
218
- }));
219
- return {
220
- props: newProps,
221
- mergeProps,
222
- deepMergeProps,
223
- deferredProps: {}
224
- };
225
- }
226
- var Inertia = class {
227
- #sharedStateProviders;
228
- #cachedRequestInfo;
229
- #serverRenderer;
230
- #vite;
231
- #shouldClearHistory;
232
- #shouldEncryptHistory;
233
- #cachedVersion;
234
- defer = defer;
235
- always = always;
236
- merge = merge;
237
- optional = optional;
238
- deepMerge = deepMerge;
239
- constructor(ctx, config, vite, serverRenderer) {
240
- this.ctx = ctx;
241
- this.config = config;
242
- if (debug_default.enabled) debug_default("instantiating inertia instance for request \"%s\" using config %O", ctx.request.url(), this.config);
243
- this.#shouldClearHistory = false;
244
- this.#vite = vite;
245
- this.#serverRenderer = serverRenderer;
246
- this.#shouldEncryptHistory = config.encryptHistory ?? false;
247
- this.#cachedVersion = this.config.assetsVersion ? String(this.config.assetsVersion) : void 0;
248
- }
249
- #resolveRootView() {
250
- return typeof this.config.rootView === "function" ? this.config.rootView(this.ctx) : this.config.rootView;
251
- }
252
- async #buildPageProps(component, requestInfo, pageProps) {
253
- let finalProps;
254
- if (this.#sharedStateProviders) finalProps = {
255
- ...await Promise.all(this.#sharedStateProviders.map((provider) => {
256
- return typeof provider === "function" ? provider() : provider;
257
- })).then((resolvedSharedState) => {
258
- return resolvedSharedState.reduce((result, state) => {
259
- return {
260
- ...result,
261
- ...state
262
- };
263
- }, {});
264
- }),
265
- ...pageProps
266
- };
267
- else finalProps = { ...pageProps };
268
- if (requestInfo.partialComponent === component) {
269
- const only = requestInfo.onlyProps;
270
- const except = requestInfo.exceptProps ?? [];
271
- const cherryPickProps = Object.keys(finalProps).filter((propName) => {
272
- if (only) return only.includes(propName) && !except.includes(propName);
273
- return !except.includes(propName);
274
- });
275
- debug_default("building props for a partial reload %O", requestInfo);
276
- debug_default("cherry picking props %s", cherryPickProps);
277
- return buildPartialRequestProps(finalProps, cherryPickProps, this.ctx.containerResolver);
278
- }
279
- debug_default("building props for a standard visit %O", requestInfo);
280
- return buildStandardVisitProps(finalProps, this.ctx.containerResolver);
281
- }
282
- #handleInertiaRequest(pageObject) {
283
- this.ctx.response.header(InertiaHeaders.Inertia, "true");
284
- return pageObject;
285
- }
286
- async #renderWithSSR(pageObject, viewProps) {
287
- if (!this.#serverRenderer) throw new Error("Cannot server render pages without a server renderer");
288
- debug_default("server-side rendering %O", pageObject);
289
- const { head, body } = await this.#serverRenderer.render(pageObject);
290
- return this.ctx.view.render(this.#resolveRootView(), {
291
- page: {
292
- ssrHead: head,
293
- ssrBody: body,
294
- ...pageObject
295
- },
296
- ...viewProps
297
- });
298
- }
299
- async #renderClientSide(pageObject, viewProps) {
300
- debug_default("rendering shell for SPA %O", pageObject);
301
- return this.ctx.view.render(this.#resolveRootView(), {
302
- page: pageObject,
303
- ...viewProps
304
- });
305
- }
306
- requestInfo(reCompute) {
307
- if (reCompute) this.#cachedRequestInfo = void 0;
308
- this.#cachedRequestInfo = this.#cachedRequestInfo ?? {
309
- version: this.ctx.request.header(InertiaHeaders.Version),
310
- isInertiaRequest: !!this.ctx.request.header(InertiaHeaders.Inertia),
311
- isPartialRequest: !!this.ctx.request.header(InertiaHeaders.PartialComponent),
312
- partialComponent: this.ctx.request.header(InertiaHeaders.PartialComponent),
313
- onlyProps: this.ctx.request.header(InertiaHeaders.PartialOnly)?.split(","),
314
- exceptProps: this.ctx.request.header(InertiaHeaders.PartialExcept)?.split(","),
315
- resetProps: this.ctx.request.header(InertiaHeaders.Reset)?.split(","),
316
- errorBag: this.ctx.request.header(InertiaHeaders.ErrorBag)
317
- };
318
- return this.#cachedRequestInfo;
319
- }
320
- getVersion() {
321
- if (this.#cachedVersion) return this.#cachedVersion;
322
- if (this.#vite?.hasManifestFile) this.#cachedVersion = createHash("md5").update(JSON.stringify(this.#vite.manifest())).digest("hex");
323
- else this.#cachedVersion = "1";
324
- return this.#cachedVersion;
325
- }
326
- async ssrEnabled(component) {
327
- if (!this.config.ssr.enabled) return false;
328
- if (typeof this.config.ssr.pages === "function") return this.config.ssr.pages(this.ctx, component);
329
- if (this.config.ssr.pages) return this.config.ssr.pages?.includes(component);
330
- return true;
331
- }
332
- share(sharedState) {
333
- if (!this.#sharedStateProviders) this.#sharedStateProviders = [];
334
- this.#sharedStateProviders.push(sharedState);
335
- return this;
336
- }
337
- async page(page, pageProps) {
338
- const requestInfo = this.requestInfo();
339
- const { props, mergeProps, deferredProps, deepMergeProps } = await this.#buildPageProps(page, requestInfo, pageProps);
340
- return {
341
- component: page,
342
- url: this.ctx.request.url(true),
343
- version: this.getVersion(),
344
- clearHistory: this.#shouldClearHistory,
345
- encryptHistory: this.#shouldEncryptHistory,
346
- props,
347
- deferredProps,
348
- mergeProps,
349
- deepMergeProps
350
- };
351
- }
352
- async render(page, pageProps, viewProps) {
353
- const requestInfo = this.requestInfo();
354
- const pageObject = await this.page(page, pageProps);
355
- if (requestInfo.isInertiaRequest) return this.#handleInertiaRequest(pageObject);
356
- if (await this.ssrEnabled(page)) return this.#renderWithSSR(pageObject, viewProps);
357
- return this.#renderClientSide(pageObject, viewProps);
358
- }
359
- clearHistory() {
360
- this.#shouldClearHistory = true;
361
- }
362
- encryptHistory(encrypt = true) {
363
- this.#shouldEncryptHistory = encrypt;
364
- }
365
- location(url) {
366
- this.ctx.response.header(InertiaHeaders.Location, url);
367
- this.ctx.response.status(409);
368
- }
369
- };
370
- var ServerRenderer = class {
371
- #runtime;
372
- #ssrEnvironment;
373
- #config;
374
- #vite;
375
- constructor(config, vite) {
376
- this.#config = config;
377
- this.#vite = vite;
378
- }
379
- async render(pageObject) {
380
- let render;
381
- const devServer = this.#vite.getDevServer();
382
- if (devServer) {
383
- debug_default("creating SSR bundle using dev-server");
384
- const currentSsrEnv = devServer.environments.ssr;
385
- if (this.#ssrEnvironment !== currentSsrEnv) {
386
- if (this.#runtime) await this.#runtime.close();
387
- this.#runtime = void 0;
388
- this.#ssrEnvironment = currentSsrEnv;
389
- }
390
- this.#runtime ??= await this.#vite.createModuleRunner();
391
- this.#runtime.clearCache();
392
- render = await this.#runtime.import(this.#config.ssr.entrypoint);
393
- } else {
394
- debug_default("creating SSR bundle using production build");
395
- render = await import(pathToFileURL(this.#config.ssr.bundle).href);
396
- }
397
- const result = await render.default(pageObject);
398
- debug_default("SSR bundle %o", result);
399
- return {
400
- head: result.head,
401
- body: result.body
402
- };
403
- }
404
- };
405
- var InertiaManager = class {
406
- #vite;
407
- #config;
408
- #serverRenderer;
409
- constructor(config, vite) {
410
- this.#config = config;
411
- this.#vite = vite;
412
- this.#serverRenderer = this.#vite ? new ServerRenderer(this.#config, this.#vite) : void 0;
413
- }
414
- createForRequest(ctx) {
415
- return new Inertia(ctx, this.#config, this.#vite, this.#serverRenderer);
416
- }
417
- };
418
- export { symbols_exports as i, ServerRenderer as n, Inertia as r, InertiaManager as t };
@@ -1,65 +0,0 @@
1
- import type { PluginOption } from 'vite';
2
- /**
3
- * Configuration options for the Inertia Vite plugin
4
- */
5
- export type InertiaPluginOptions = {
6
- /**
7
- * Server-side rendering configuration
8
- */
9
- ssr?: {
10
- /**
11
- * Whether or not to enable server-side rendering
12
- */
13
- enabled: true;
14
- /**
15
- * The entrypoint for the server-side rendering
16
- */
17
- entrypoint: string;
18
- /**
19
- * The output directory for the server-side rendering bundle
20
- */
21
- output?: string;
22
- } | {
23
- enabled: false;
24
- entrypoint?: string;
25
- output?: string;
26
- };
27
- };
28
- /**
29
- * Inertia plugin for Vite that is tailored for AdonisJS
30
- *
31
- * Configures Vite for Inertia.js development with proper build settings,
32
- * SSR support, and AdonisJS-specific optimizations.
33
- *
34
- * @param options - Configuration options for the plugin
35
- * @returns Vite plugin configuration object
36
- *
37
- * @example
38
- * ```js
39
- * // Basic configuration
40
- * import inertia from '@adonisjs/inertia/plugins/vite'
41
- *
42
- * export default defineConfig({
43
- * plugins: [inertia()]
44
- * })
45
- * ```
46
- *
47
- * @example
48
- * ```js
49
- * // With SSR enabled
50
- * import inertia from '@adonisjs/inertia/plugins/vite'
51
- *
52
- * export default defineConfig({
53
- * plugins: [
54
- * inertia({
55
- * ssr: {
56
- * enabled: true,
57
- * entrypoint: 'inertia/ssr.tsx',
58
- * output: 'build/ssr'
59
- * }
60
- * })
61
- * ]
62
- * })
63
- * ```
64
- */
65
- export default function inertia(options?: InertiaPluginOptions): PluginOption;
@@ -1,21 +0,0 @@
1
- function inertia(options) {
2
- return {
3
- name: "vite-plugin-inertia",
4
- config: (_, { command }) => {
5
- if (command === "build") process.env.NODE_ENV = "production";
6
- return {
7
- builder: { buildApp: async (builder) => {
8
- await builder.build(builder.environments.client);
9
- if (options?.ssr?.enabled) await builder.build(builder.environments.ssr);
10
- } },
11
- build: { outDir: "build/public/assets" },
12
- environments: { ...options?.ssr?.enabled && { ssr: { build: {
13
- ssr: true,
14
- outDir: options.ssr.output || "build/ssr",
15
- rollupOptions: { input: options.ssr.entrypoint }
16
- } } } }
17
- };
18
- }
19
- };
20
- }
21
- export { inertia as default };