@adonisjs/inertia 1.0.0-19 → 1.0.0-20

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.
@@ -150,12 +150,23 @@ var Inertia = class {
150
150
  };
151
151
  }
152
152
  /**
153
- * If the page should be rendered on the server
153
+ * If the page should be rendered on the server or not
154
+ *
155
+ * The ssr.pages config can be a list of pages or a function that returns a boolean
154
156
  */
155
- #shouldRenderOnServer(component) {
157
+ async #shouldRenderOnServer(component) {
156
158
  const isSsrEnabled = this.config.ssr.enabled;
157
- const isSsrEnabledForPage = this.config.ssr.pages ? this.config.ssr.pages.includes(component) : true;
158
- return isSsrEnabled && isSsrEnabledForPage;
159
+ if (!isSsrEnabled)
160
+ return false;
161
+ let isSsrEnabledForPage = false;
162
+ if (typeof this.config.ssr.pages === "function") {
163
+ isSsrEnabledForPage = await this.config.ssr.pages(this.ctx, component);
164
+ } else if (this.config.ssr.pages) {
165
+ isSsrEnabledForPage = this.config.ssr.pages?.includes(component);
166
+ } else {
167
+ isSsrEnabledForPage = true;
168
+ }
169
+ return isSsrEnabledForPage;
159
170
  }
160
171
  /**
161
172
  * Render the page on the server
@@ -181,7 +192,7 @@ var Inertia = class {
181
192
  const pageObject = await this.#buildPageObject(component, pageProps);
182
193
  const isInertiaRequest = !!this.ctx.request.header("x-inertia");
183
194
  if (!isInertiaRequest) {
184
- const shouldRenderOnServer = this.#shouldRenderOnServer(component);
195
+ const shouldRenderOnServer = await this.#shouldRenderOnServer(component);
185
196
  if (shouldRenderOnServer)
186
197
  return this.#renderOnServer(pageObject, viewProps);
187
198
  return this.ctx.view.render(this.config.rootView, { ...viewProps, page: pageObject });
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  InertiaMiddleware
3
- } from "../chunk-7ZZGYDYU.js";
3
+ } from "../chunk-PJEYAPJB.js";
4
4
 
5
5
  // providers/inertia_provider.ts
6
6
  import { configProvider } from "@adonisjs/core";
@@ -8,7 +8,7 @@
8
8
  "module": "ESNext",
9
9
  "jsx": "react-jsx",
10
10
  "paths": {
11
- "~/*": ["../*"],
11
+ "~/*": ["./*"],
12
12
  },
13
13
  },
14
14
  "include": ["./**/*.ts", "./**/*.tsx"],
@@ -24,7 +24,7 @@ declare class Inertia {
24
24
  /**
25
25
  * Render a page using Inertia
26
26
  */
27
- render<TPageProps extends Record<string, any> = PageProps, TViewProps extends Record<string, any> = PageProps>(component: string, pageProps?: TPageProps, viewProps?: TViewProps): Promise<string | PageObject>;
27
+ render<TPageProps extends Record<string, any> = PageProps, TViewProps extends Record<string, any> = PageProps>(component: string, pageProps?: TPageProps, viewProps?: TViewProps): Promise<string | PageObject<TPageProps>>;
28
28
  /**
29
29
  * Create a lazy prop
30
30
  *
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  InertiaMiddleware
3
- } from "../chunk-7ZZGYDYU.js";
3
+ } from "../chunk-PJEYAPJB.js";
4
4
  export {
5
5
  InertiaMiddleware as default
6
6
  };
@@ -71,7 +71,7 @@ interface InertiaConfig {
71
71
  /**
72
72
  * List of components that should be rendered on the server
73
73
  */
74
- pages?: string[];
74
+ pages?: string[] | ((ctx: HttpContext, page: string) => MaybePromise<boolean>);
75
75
  /**
76
76
  * Path to the SSR entrypoint file
77
77
  */
@@ -93,14 +93,14 @@ interface ResolvedConfig {
93
93
  ssr: {
94
94
  enabled: boolean;
95
95
  entrypoint: string;
96
- pages?: string[];
96
+ pages?: string[] | ((ctx: HttpContext, page: string) => MaybePromise<boolean>);
97
97
  bundle: string;
98
98
  };
99
99
  }
100
- interface PageObject {
100
+ interface PageObject<TPageProps extends PageProps = PageProps> {
101
101
  component: string;
102
102
  version: string | number;
103
- props: PageProps;
103
+ props: TPageProps;
104
104
  url: string;
105
105
  ssrHead?: string;
106
106
  ssrBody?: string;
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": "1.0.0-19",
4
+ "version": "1.0.0-20",
5
5
  "engines": {
6
6
  "node": ">=18.16.0"
7
7
  },
@@ -40,11 +40,11 @@
40
40
  "devDependencies": {
41
41
  "@adonisjs/assembler": "^7.2.3",
42
42
  "@adonisjs/core": "6.3.1",
43
- "@adonisjs/eslint-config": "^1.2.2",
44
- "@adonisjs/prettier-config": "^1.2.2",
45
- "@adonisjs/session": "7.1.1",
46
- "@adonisjs/tsconfig": "^1.2.2",
47
- "@adonisjs/vite": "^3.0.0-6",
43
+ "@adonisjs/eslint-config": "^1.3.0",
44
+ "@adonisjs/prettier-config": "^1.3.0",
45
+ "@adonisjs/session": "7.3.0",
46
+ "@adonisjs/tsconfig": "^1.3.0",
47
+ "@adonisjs/vite": "^3.0.0-8",
48
48
  "@japa/api-client": "^2.0.2",
49
49
  "@japa/assert": "2.1.0",
50
50
  "@japa/expect-type": "^2.0.1",
@@ -52,39 +52,39 @@
52
52
  "@japa/plugin-adonisjs": "^3.0.0",
53
53
  "@japa/runner": "3.1.1",
54
54
  "@japa/snapshot": "^2.0.4",
55
- "@swc/core": "^1.4.2",
56
- "@types/node": "^20.11.24",
57
- "@types/qs": "^6.9.12",
55
+ "@swc/core": "^1.4.8",
56
+ "@types/node": "^20.11.30",
57
+ "@types/qs": "^6.9.14",
58
58
  "@types/supertest": "^6.0.2",
59
59
  "@vavite/multibuild": "^4.1.1",
60
60
  "c8": "^9.1.0",
61
61
  "copyfiles": "^2.4.1",
62
62
  "del-cli": "^5.1.0",
63
- "edge-parser": "^9.0.1",
64
- "edge.js": "^6.0.1",
63
+ "edge-parser": "^9.0.2",
64
+ "edge.js": "^6.0.2",
65
65
  "eslint": "^8.57.0",
66
- "get-port": "^7.0.0",
67
- "np": "^10.0.0",
66
+ "get-port": "^7.1.0",
67
+ "np": "^10.0.2",
68
68
  "prettier": "^3.2.5",
69
69
  "supertest": "^6.3.4",
70
70
  "tinybench": "^2.6.0",
71
71
  "ts-node": "^10.9.2",
72
72
  "tsup": "^8.0.2",
73
- "typescript": "~5.3.3",
74
- "vite": "^5.1.4"
73
+ "typescript": "~5.4.3",
74
+ "vite": "^5.2.6"
75
75
  },
76
76
  "dependencies": {
77
77
  "@poppinss/utils": "^6.7.2",
78
78
  "crc-32": "^1.2.2",
79
79
  "edge-error": "^4.0.1",
80
- "html-entities": "^2.4.0",
80
+ "html-entities": "^2.5.2",
81
81
  "locate-path": "^7.2.0",
82
82
  "qs": "^6.11.2"
83
83
  },
84
84
  "peerDependencies": {
85
85
  "@adonisjs/core": "^6.2.0",
86
86
  "@adonisjs/session": "^7.0.0",
87
- "@adonisjs/vite": "^3.0.0-6",
87
+ "@adonisjs/vite": "^3.0.0-8",
88
88
  "@japa/api-client": "^2.0.0",
89
89
  "edge.js": "^6.0.0"
90
90
  },