@btst/stack 2.9.2 → 2.9.4

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 (42) hide show
  1. package/dist/packages/stack/src/plugins/blog/client/plugin.cjs +22 -11
  2. package/dist/packages/stack/src/plugins/blog/client/plugin.mjs +22 -11
  3. package/dist/packages/stack/src/plugins/cms/client/plugin.cjs +71 -39
  4. package/dist/packages/stack/src/plugins/cms/client/plugin.mjs +71 -39
  5. package/dist/packages/stack/src/plugins/comments/client/plugin.cjs +62 -2
  6. package/dist/packages/stack/src/plugins/comments/client/plugin.mjs +63 -3
  7. package/dist/packages/stack/src/plugins/comments/client/utils.cjs +2 -11
  8. package/dist/packages/stack/src/plugins/comments/client/utils.mjs +2 -11
  9. package/dist/packages/stack/src/plugins/comments/error-utils.cjs +15 -0
  10. package/dist/packages/stack/src/plugins/comments/error-utils.mjs +13 -0
  11. package/dist/packages/stack/src/plugins/form-builder/client/plugin.cjs +59 -31
  12. package/dist/packages/stack/src/plugins/form-builder/client/plugin.mjs +59 -31
  13. package/dist/packages/stack/src/plugins/media/db.cjs +10 -2
  14. package/dist/packages/stack/src/plugins/media/db.mjs +10 -2
  15. package/dist/packages/stack/src/plugins/ui-builder/client/plugin.cjs +52 -25
  16. package/dist/packages/stack/src/plugins/ui-builder/client/plugin.mjs +53 -26
  17. package/dist/packages/stack/src/plugins/utils.cjs +6 -0
  18. package/dist/packages/stack/src/plugins/utils.mjs +5 -1
  19. package/dist/plugins/client/index.cjs +2 -0
  20. package/dist/plugins/client/index.d.cts +15 -1
  21. package/dist/plugins/client/index.d.mts +15 -1
  22. package/dist/plugins/client/index.d.ts +15 -1
  23. package/dist/plugins/client/index.mjs +1 -1
  24. package/dist/plugins/comments/client/index.d.cts +5 -0
  25. package/dist/plugins/comments/client/index.d.mts +5 -0
  26. package/dist/plugins/comments/client/index.d.ts +5 -0
  27. package/dist/plugins/comments/query-keys.cjs +4 -4
  28. package/dist/plugins/comments/query-keys.mjs +1 -1
  29. package/package.json +1 -1
  30. package/src/__tests__/client-plugin-ssr-loaders.test.ts +329 -0
  31. package/src/plugins/blog/client/plugin.tsx +23 -14
  32. package/src/plugins/client/index.ts +2 -0
  33. package/src/plugins/cms/client/plugin.tsx +73 -42
  34. package/src/plugins/comments/client/plugin.tsx +82 -2
  35. package/src/plugins/comments/client/utils.ts +2 -14
  36. package/src/plugins/comments/error-utils.ts +17 -0
  37. package/src/plugins/comments/query-keys.ts +1 -1
  38. package/src/plugins/form-builder/client/plugin.tsx +59 -35
  39. package/src/plugins/media/__tests__/plugin.test.ts +4 -4
  40. package/src/plugins/media/db.ts +8 -0
  41. package/src/plugins/ui-builder/client/plugin.tsx +57 -27
  42. package/src/plugins/utils.ts +18 -0
@@ -3,6 +3,7 @@
3
3
  const jsxRuntime = require('react/jsx-runtime');
4
4
  const client = require('@btst/stack/plugins/client');
5
5
  const yar = require('@btst/yar');
6
+ const utils = require('../../utils.cjs');
6
7
  const plugins_blog_queryKeys = require('../../../../../../plugins/blog/query-keys.cjs');
7
8
  const homePage = require('./components/pages/home-page.cjs');
8
9
  const newPostPage = require('./components/pages/new-post-page.cjs');
@@ -21,6 +22,17 @@ function createPostsLoader(published, config) {
21
22
  apiBasePath,
22
23
  headers
23
24
  };
25
+ const limit = 10;
26
+ const client$1 = client.createApiClient({
27
+ baseURL: apiBaseURL,
28
+ basePath: apiBasePath
29
+ });
30
+ const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1, headers);
31
+ const listQuery = queries.posts.list({
32
+ query: void 0,
33
+ limit,
34
+ published
35
+ });
24
36
  try {
25
37
  if (hooks?.beforeLoadPosts) {
26
38
  await client.runClientHookWithShim(
@@ -28,17 +40,6 @@ function createPostsLoader(published, config) {
28
40
  "Load prevented by beforeLoadPosts hook"
29
41
  );
30
42
  }
31
- const limit = 10;
32
- const client$1 = client.createApiClient({
33
- baseURL: apiBaseURL,
34
- basePath: apiBasePath
35
- });
36
- const queries = plugins_blog_queryKeys.createBlogQueryKeys(client$1, headers);
37
- const listQuery = queries.posts.list({
38
- query: void 0,
39
- limit,
40
- published
41
- });
42
43
  await queryClient.prefetchInfiniteQuery({
43
44
  ...listQuery,
44
45
  initialPageParam: 0
@@ -64,6 +65,16 @@ function createPostsLoader(published, config) {
64
65
  console.warn(
65
66
  "[btst/blog] route.loader() failed \u2014 no server running at build time. Use myStack.api.blog.prefetchForRoute() for SSG data prefetching."
66
67
  );
68
+ } else {
69
+ const errToStore = utils.createSanitizedSSRLoaderError();
70
+ await queryClient.prefetchInfiniteQuery({
71
+ queryKey: listQuery.queryKey,
72
+ queryFn: () => {
73
+ throw errToStore;
74
+ },
75
+ initialPageParam: 0,
76
+ retry: false
77
+ });
67
78
  }
68
79
  if (hooks?.onLoadError) {
69
80
  await hooks.onLoadError(error, context);
@@ -1,6 +1,7 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
2
  import { defineClientPlugin, createApiClient, runClientHookWithShim, isConnectionError } from '@btst/stack/plugins/client';
3
3
  import { createRoute } from '@btst/yar';
4
+ import { createSanitizedSSRLoaderError } from '../../utils.mjs';
4
5
  import { createBlogQueryKeys } from '../../../../../../plugins/blog/query-keys.mjs';
5
6
  import { HomePageComponent } from './components/pages/home-page.mjs';
6
7
  import { NewPostPageComponent } from './components/pages/new-post-page.mjs';
@@ -19,6 +20,17 @@ function createPostsLoader(published, config) {
19
20
  apiBasePath,
20
21
  headers
21
22
  };
23
+ const limit = 10;
24
+ const client = createApiClient({
25
+ baseURL: apiBaseURL,
26
+ basePath: apiBasePath
27
+ });
28
+ const queries = createBlogQueryKeys(client, headers);
29
+ const listQuery = queries.posts.list({
30
+ query: void 0,
31
+ limit,
32
+ published
33
+ });
22
34
  try {
23
35
  if (hooks?.beforeLoadPosts) {
24
36
  await runClientHookWithShim(
@@ -26,17 +38,6 @@ function createPostsLoader(published, config) {
26
38
  "Load prevented by beforeLoadPosts hook"
27
39
  );
28
40
  }
29
- const limit = 10;
30
- const client = createApiClient({
31
- baseURL: apiBaseURL,
32
- basePath: apiBasePath
33
- });
34
- const queries = createBlogQueryKeys(client, headers);
35
- const listQuery = queries.posts.list({
36
- query: void 0,
37
- limit,
38
- published
39
- });
40
41
  await queryClient.prefetchInfiniteQuery({
41
42
  ...listQuery,
42
43
  initialPageParam: 0
@@ -62,6 +63,16 @@ function createPostsLoader(published, config) {
62
63
  console.warn(
63
64
  "[btst/blog] route.loader() failed \u2014 no server running at build time. Use myStack.api.blog.prefetchForRoute() for SSG data prefetching."
64
65
  );
66
+ } else {
67
+ const errToStore = createSanitizedSSRLoaderError();
68
+ await queryClient.prefetchInfiniteQuery({
69
+ queryKey: listQuery.queryKey,
70
+ queryFn: () => {
71
+ throw errToStore;
72
+ },
73
+ initialPageParam: 0,
74
+ retry: false
75
+ });
65
76
  }
66
77
  if (hooks?.onLoadError) {
67
78
  await hooks.onLoadError(error, context);
@@ -4,6 +4,7 @@ const jsxRuntime = require('react/jsx-runtime');
4
4
  const React = require('react');
5
5
  const client = require('@btst/stack/plugins/client');
6
6
  const yar = require('@btst/yar');
7
+ const utils = require('../../utils.cjs');
7
8
  const plugins_cms_queryKeys = require('../../../../../../plugins/cms/query-keys.cjs');
8
9
 
9
10
  const DashboardPageComponent = React.lazy(
@@ -32,6 +33,12 @@ function createDashboardLoader(config) {
32
33
  apiBasePath,
33
34
  headers
34
35
  };
36
+ const client$1 = client.createApiClient({
37
+ baseURL: apiBaseURL,
38
+ basePath: apiBasePath
39
+ });
40
+ const queries = plugins_cms_queryKeys.createCMSQueryKeys(client$1, headers);
41
+ const typesQuery = queries.cmsTypes.list();
35
42
  try {
36
43
  if (hooks?.beforeLoadDashboard) {
37
44
  await client.runClientHookWithShim(
@@ -39,18 +46,11 @@ function createDashboardLoader(config) {
39
46
  "Load prevented by beforeLoadDashboard hook"
40
47
  );
41
48
  }
42
- const client$1 = client.createApiClient({
43
- baseURL: apiBaseURL,
44
- basePath: apiBasePath
45
- });
46
- const queries = plugins_cms_queryKeys.createCMSQueryKeys(client$1, headers);
47
- await queryClient.prefetchQuery(queries.cmsTypes.list());
49
+ await queryClient.prefetchQuery(typesQuery);
48
50
  if (hooks?.afterLoadDashboard) {
49
51
  await hooks.afterLoadDashboard(context);
50
52
  }
51
- const queryState = queryClient.getQueryState(
52
- queries.cmsTypes.list().queryKey
53
- );
53
+ const queryState = queryClient.getQueryState(typesQuery.queryKey);
54
54
  if (queryState?.error && hooks?.onLoadError) {
55
55
  const error = queryState.error instanceof Error ? queryState.error : new Error(String(queryState.error));
56
56
  await hooks.onLoadError(error, context);
@@ -60,6 +60,15 @@ function createDashboardLoader(config) {
60
60
  console.warn(
61
61
  "[btst/cms] route.loader() failed \u2014 no server running at build time. Use myStack.api.cms.prefetchForRoute() for SSG data prefetching."
62
62
  );
63
+ } else {
64
+ const errToStore = utils.createSanitizedSSRLoaderError();
65
+ await queryClient.prefetchQuery({
66
+ queryKey: typesQuery.queryKey,
67
+ queryFn: () => {
68
+ throw errToStore;
69
+ },
70
+ retry: false
71
+ });
63
72
  }
64
73
  if (hooks?.onLoadError) {
65
74
  await hooks.onLoadError(error, context);
@@ -80,6 +89,18 @@ function createContentListLoader(typeSlug, config) {
80
89
  apiBasePath,
81
90
  headers
82
91
  };
92
+ const client$1 = client.createApiClient({
93
+ baseURL: apiBaseURL,
94
+ basePath: apiBasePath
95
+ });
96
+ const queries = plugins_cms_queryKeys.createCMSQueryKeys(client$1, headers);
97
+ const limit = 20;
98
+ const typesQuery = queries.cmsTypes.list();
99
+ const listQuery = queries.cmsContent.list({
100
+ typeSlug,
101
+ limit,
102
+ offset: 0
103
+ });
83
104
  try {
84
105
  if (hooks?.beforeLoadContentList) {
85
106
  await client.runClientHookWithShim(
@@ -87,18 +108,7 @@ function createContentListLoader(typeSlug, config) {
87
108
  "Load prevented by beforeLoadContentList hook"
88
109
  );
89
110
  }
90
- const client$1 = client.createApiClient({
91
- baseURL: apiBaseURL,
92
- basePath: apiBasePath
93
- });
94
- const queries = plugins_cms_queryKeys.createCMSQueryKeys(client$1, headers);
95
- const limit = 20;
96
- await queryClient.prefetchQuery(queries.cmsTypes.list());
97
- const listQuery = queries.cmsContent.list({
98
- typeSlug,
99
- limit,
100
- offset: 0
101
- });
111
+ await queryClient.prefetchQuery(typesQuery);
102
112
  await queryClient.prefetchInfiniteQuery({
103
113
  queryKey: listQuery.queryKey,
104
114
  queryFn: async ({ pageParam = 0 }) => {
@@ -118,9 +128,7 @@ function createContentListLoader(typeSlug, config) {
118
128
  if (hooks?.afterLoadContentList) {
119
129
  await hooks.afterLoadContentList(typeSlug, context);
120
130
  }
121
- const typesState = queryClient.getQueryState(
122
- queries.cmsTypes.list().queryKey
123
- );
131
+ const typesState = queryClient.getQueryState(typesQuery.queryKey);
124
132
  const listState = queryClient.getQueryState(listQuery.queryKey);
125
133
  const queryError = typesState?.error || listState?.error;
126
134
  if (queryError && hooks?.onLoadError) {
@@ -132,6 +140,16 @@ function createContentListLoader(typeSlug, config) {
132
140
  console.warn(
133
141
  "[btst/cms] route.loader() failed \u2014 no server running at build time. Use myStack.api.cms.prefetchForRoute() for SSG data prefetching."
134
142
  );
143
+ } else {
144
+ const errToStore = utils.createSanitizedSSRLoaderError();
145
+ await queryClient.prefetchInfiniteQuery({
146
+ queryKey: listQuery.queryKey,
147
+ queryFn: () => {
148
+ throw errToStore;
149
+ },
150
+ initialPageParam: 0,
151
+ retry: false
152
+ });
135
153
  }
136
154
  if (hooks?.onLoadError) {
137
155
  await hooks.onLoadError(error, context);
@@ -152,6 +170,13 @@ function createContentEditorLoader(typeSlug, id, config) {
152
170
  apiBasePath,
153
171
  headers
154
172
  };
173
+ const client$1 = client.createApiClient({
174
+ baseURL: apiBaseURL,
175
+ basePath: apiBasePath
176
+ });
177
+ const queries = plugins_cms_queryKeys.createCMSQueryKeys(client$1, headers);
178
+ const typesQuery = queries.cmsTypes.list();
179
+ const detailQuery = id ? queries.cmsContent.detail(typeSlug, id) : void 0;
155
180
  try {
156
181
  if (hooks?.beforeLoadContentEditor) {
157
182
  await client.runClientHookWithShim(
@@ -159,27 +184,16 @@ function createContentEditorLoader(typeSlug, id, config) {
159
184
  "Load prevented by beforeLoadContentEditor hook"
160
185
  );
161
186
  }
162
- const client$1 = client.createApiClient({
163
- baseURL: apiBaseURL,
164
- basePath: apiBasePath
165
- });
166
- const queries = plugins_cms_queryKeys.createCMSQueryKeys(client$1, headers);
167
- const promises = [queryClient.prefetchQuery(queries.cmsTypes.list())];
187
+ const promises = [queryClient.prefetchQuery(typesQuery)];
168
188
  if (id) {
169
- promises.push(
170
- queryClient.prefetchQuery(queries.cmsContent.detail(typeSlug, id))
171
- );
189
+ promises.push(queryClient.prefetchQuery(detailQuery));
172
190
  }
173
191
  await Promise.all(promises);
174
192
  if (hooks?.afterLoadContentEditor) {
175
193
  await hooks.afterLoadContentEditor(typeSlug, id, context);
176
194
  }
177
- const typesState = queryClient.getQueryState(
178
- queries.cmsTypes.list().queryKey
179
- );
180
- const itemState = id ? queryClient.getQueryState(
181
- queries.cmsContent.detail(typeSlug, id).queryKey
182
- ) : null;
195
+ const typesState = queryClient.getQueryState(typesQuery.queryKey);
196
+ const itemState = id ? queryClient.getQueryState(detailQuery.queryKey) : null;
183
197
  const queryError = typesState?.error || itemState?.error;
184
198
  if (queryError && hooks?.onLoadError) {
185
199
  const error = queryError instanceof Error ? queryError : new Error(String(queryError));
@@ -190,6 +204,24 @@ function createContentEditorLoader(typeSlug, id, config) {
190
204
  console.warn(
191
205
  "[btst/cms] route.loader() failed \u2014 no server running at build time. Use myStack.api.cms.prefetchForRoute() for SSG data prefetching."
192
206
  );
207
+ } else {
208
+ const errToStore = utils.createSanitizedSSRLoaderError();
209
+ await queryClient.prefetchQuery({
210
+ queryKey: typesQuery.queryKey,
211
+ queryFn: () => {
212
+ throw errToStore;
213
+ },
214
+ retry: false
215
+ });
216
+ if (detailQuery) {
217
+ await queryClient.prefetchQuery({
218
+ queryKey: detailQuery.queryKey,
219
+ queryFn: () => {
220
+ throw errToStore;
221
+ },
222
+ retry: false
223
+ });
224
+ }
193
225
  }
194
226
  if (hooks?.onLoadError) {
195
227
  await hooks.onLoadError(error, context);
@@ -2,6 +2,7 @@ import { jsx } from 'react/jsx-runtime';
2
2
  import { lazy } from 'react';
3
3
  import { defineClientPlugin, createApiClient, runClientHookWithShim, isConnectionError } from '@btst/stack/plugins/client';
4
4
  import { createRoute } from '@btst/yar';
5
+ import { createSanitizedSSRLoaderError } from '../../utils.mjs';
5
6
  import { createCMSQueryKeys } from '../../../../../../plugins/cms/query-keys.mjs';
6
7
 
7
8
  const DashboardPageComponent = lazy(
@@ -30,6 +31,12 @@ function createDashboardLoader(config) {
30
31
  apiBasePath,
31
32
  headers
32
33
  };
34
+ const client = createApiClient({
35
+ baseURL: apiBaseURL,
36
+ basePath: apiBasePath
37
+ });
38
+ const queries = createCMSQueryKeys(client, headers);
39
+ const typesQuery = queries.cmsTypes.list();
33
40
  try {
34
41
  if (hooks?.beforeLoadDashboard) {
35
42
  await runClientHookWithShim(
@@ -37,18 +44,11 @@ function createDashboardLoader(config) {
37
44
  "Load prevented by beforeLoadDashboard hook"
38
45
  );
39
46
  }
40
- const client = createApiClient({
41
- baseURL: apiBaseURL,
42
- basePath: apiBasePath
43
- });
44
- const queries = createCMSQueryKeys(client, headers);
45
- await queryClient.prefetchQuery(queries.cmsTypes.list());
47
+ await queryClient.prefetchQuery(typesQuery);
46
48
  if (hooks?.afterLoadDashboard) {
47
49
  await hooks.afterLoadDashboard(context);
48
50
  }
49
- const queryState = queryClient.getQueryState(
50
- queries.cmsTypes.list().queryKey
51
- );
51
+ const queryState = queryClient.getQueryState(typesQuery.queryKey);
52
52
  if (queryState?.error && hooks?.onLoadError) {
53
53
  const error = queryState.error instanceof Error ? queryState.error : new Error(String(queryState.error));
54
54
  await hooks.onLoadError(error, context);
@@ -58,6 +58,15 @@ function createDashboardLoader(config) {
58
58
  console.warn(
59
59
  "[btst/cms] route.loader() failed \u2014 no server running at build time. Use myStack.api.cms.prefetchForRoute() for SSG data prefetching."
60
60
  );
61
+ } else {
62
+ const errToStore = createSanitizedSSRLoaderError();
63
+ await queryClient.prefetchQuery({
64
+ queryKey: typesQuery.queryKey,
65
+ queryFn: () => {
66
+ throw errToStore;
67
+ },
68
+ retry: false
69
+ });
61
70
  }
62
71
  if (hooks?.onLoadError) {
63
72
  await hooks.onLoadError(error, context);
@@ -78,6 +87,18 @@ function createContentListLoader(typeSlug, config) {
78
87
  apiBasePath,
79
88
  headers
80
89
  };
90
+ const client = createApiClient({
91
+ baseURL: apiBaseURL,
92
+ basePath: apiBasePath
93
+ });
94
+ const queries = createCMSQueryKeys(client, headers);
95
+ const limit = 20;
96
+ const typesQuery = queries.cmsTypes.list();
97
+ const listQuery = queries.cmsContent.list({
98
+ typeSlug,
99
+ limit,
100
+ offset: 0
101
+ });
81
102
  try {
82
103
  if (hooks?.beforeLoadContentList) {
83
104
  await runClientHookWithShim(
@@ -85,18 +106,7 @@ function createContentListLoader(typeSlug, config) {
85
106
  "Load prevented by beforeLoadContentList hook"
86
107
  );
87
108
  }
88
- const client = createApiClient({
89
- baseURL: apiBaseURL,
90
- basePath: apiBasePath
91
- });
92
- const queries = createCMSQueryKeys(client, headers);
93
- const limit = 20;
94
- await queryClient.prefetchQuery(queries.cmsTypes.list());
95
- const listQuery = queries.cmsContent.list({
96
- typeSlug,
97
- limit,
98
- offset: 0
99
- });
109
+ await queryClient.prefetchQuery(typesQuery);
100
110
  await queryClient.prefetchInfiniteQuery({
101
111
  queryKey: listQuery.queryKey,
102
112
  queryFn: async ({ pageParam = 0 }) => {
@@ -116,9 +126,7 @@ function createContentListLoader(typeSlug, config) {
116
126
  if (hooks?.afterLoadContentList) {
117
127
  await hooks.afterLoadContentList(typeSlug, context);
118
128
  }
119
- const typesState = queryClient.getQueryState(
120
- queries.cmsTypes.list().queryKey
121
- );
129
+ const typesState = queryClient.getQueryState(typesQuery.queryKey);
122
130
  const listState = queryClient.getQueryState(listQuery.queryKey);
123
131
  const queryError = typesState?.error || listState?.error;
124
132
  if (queryError && hooks?.onLoadError) {
@@ -130,6 +138,16 @@ function createContentListLoader(typeSlug, config) {
130
138
  console.warn(
131
139
  "[btst/cms] route.loader() failed \u2014 no server running at build time. Use myStack.api.cms.prefetchForRoute() for SSG data prefetching."
132
140
  );
141
+ } else {
142
+ const errToStore = createSanitizedSSRLoaderError();
143
+ await queryClient.prefetchInfiniteQuery({
144
+ queryKey: listQuery.queryKey,
145
+ queryFn: () => {
146
+ throw errToStore;
147
+ },
148
+ initialPageParam: 0,
149
+ retry: false
150
+ });
133
151
  }
134
152
  if (hooks?.onLoadError) {
135
153
  await hooks.onLoadError(error, context);
@@ -150,6 +168,13 @@ function createContentEditorLoader(typeSlug, id, config) {
150
168
  apiBasePath,
151
169
  headers
152
170
  };
171
+ const client = createApiClient({
172
+ baseURL: apiBaseURL,
173
+ basePath: apiBasePath
174
+ });
175
+ const queries = createCMSQueryKeys(client, headers);
176
+ const typesQuery = queries.cmsTypes.list();
177
+ const detailQuery = id ? queries.cmsContent.detail(typeSlug, id) : void 0;
153
178
  try {
154
179
  if (hooks?.beforeLoadContentEditor) {
155
180
  await runClientHookWithShim(
@@ -157,27 +182,16 @@ function createContentEditorLoader(typeSlug, id, config) {
157
182
  "Load prevented by beforeLoadContentEditor hook"
158
183
  );
159
184
  }
160
- const client = createApiClient({
161
- baseURL: apiBaseURL,
162
- basePath: apiBasePath
163
- });
164
- const queries = createCMSQueryKeys(client, headers);
165
- const promises = [queryClient.prefetchQuery(queries.cmsTypes.list())];
185
+ const promises = [queryClient.prefetchQuery(typesQuery)];
166
186
  if (id) {
167
- promises.push(
168
- queryClient.prefetchQuery(queries.cmsContent.detail(typeSlug, id))
169
- );
187
+ promises.push(queryClient.prefetchQuery(detailQuery));
170
188
  }
171
189
  await Promise.all(promises);
172
190
  if (hooks?.afterLoadContentEditor) {
173
191
  await hooks.afterLoadContentEditor(typeSlug, id, context);
174
192
  }
175
- const typesState = queryClient.getQueryState(
176
- queries.cmsTypes.list().queryKey
177
- );
178
- const itemState = id ? queryClient.getQueryState(
179
- queries.cmsContent.detail(typeSlug, id).queryKey
180
- ) : null;
193
+ const typesState = queryClient.getQueryState(typesQuery.queryKey);
194
+ const itemState = id ? queryClient.getQueryState(detailQuery.queryKey) : null;
181
195
  const queryError = typesState?.error || itemState?.error;
182
196
  if (queryError && hooks?.onLoadError) {
183
197
  const error = queryError instanceof Error ? queryError : new Error(String(queryError));
@@ -188,6 +202,24 @@ function createContentEditorLoader(typeSlug, id, config) {
188
202
  console.warn(
189
203
  "[btst/cms] route.loader() failed \u2014 no server running at build time. Use myStack.api.cms.prefetchForRoute() for SSG data prefetching."
190
204
  );
205
+ } else {
206
+ const errToStore = createSanitizedSSRLoaderError();
207
+ await queryClient.prefetchQuery({
208
+ queryKey: typesQuery.queryKey,
209
+ queryFn: () => {
210
+ throw errToStore;
211
+ },
212
+ retry: false
213
+ });
214
+ if (detailQuery) {
215
+ await queryClient.prefetchQuery({
216
+ queryKey: detailQuery.queryKey,
217
+ queryFn: () => {
218
+ throw errToStore;
219
+ },
220
+ retry: false
221
+ });
222
+ }
191
223
  }
192
224
  if (hooks?.onLoadError) {
193
225
  await hooks.onLoadError(error, context);
@@ -3,6 +3,8 @@
3
3
  const React = require('react');
4
4
  const client = require('@btst/stack/plugins/client');
5
5
  const yar = require('@btst/yar');
6
+ const plugins_comments_queryKeys = require('../../../../../../plugins/comments/query-keys.cjs');
7
+ const utils = require('../../utils.cjs');
6
8
 
7
9
  const ModerationPageComponent = React.lazy(
8
10
  () => import('./components/pages/moderation-page.cjs').then((m) => ({
@@ -17,7 +19,7 @@ const UserCommentsPageComponent = React.lazy(
17
19
  function createModerationLoader(config) {
18
20
  return async () => {
19
21
  if (typeof window === "undefined") {
20
- const { apiBasePath, apiBaseURL, headers, hooks } = config;
22
+ const { queryClient, apiBasePath, apiBaseURL, headers, hooks } = config;
21
23
  const context = {
22
24
  path: "/comments/moderation",
23
25
  isSSR: true,
@@ -25,15 +27,40 @@ function createModerationLoader(config) {
25
27
  apiBasePath,
26
28
  headers
27
29
  };
30
+ const client$1 = client.createApiClient({
31
+ baseURL: apiBaseURL,
32
+ basePath: apiBasePath
33
+ });
34
+ const queries = plugins_comments_queryKeys.createCommentsQueryKeys(client$1, headers);
35
+ const listQuery = queries.comments.list({
36
+ status: "pending",
37
+ limit: 20,
38
+ offset: 0
39
+ });
28
40
  try {
29
41
  if (hooks?.beforeLoadModeration) {
30
42
  await hooks.beforeLoadModeration(context);
31
43
  }
44
+ await queryClient.prefetchQuery(listQuery);
45
+ const queryState = queryClient.getQueryState(listQuery.queryKey);
46
+ if (queryState?.error && hooks?.onLoadError) {
47
+ const error = queryState.error instanceof Error ? queryState.error : new Error(String(queryState.error));
48
+ await hooks.onLoadError(error, context);
49
+ }
32
50
  } catch (error) {
33
51
  if (client.isConnectionError(error)) {
34
52
  console.warn(
35
53
  "[btst/comments] route.loader() failed \u2014 no server running at build time."
36
54
  );
55
+ } else {
56
+ const errToStore = utils.createSanitizedSSRLoaderError();
57
+ await queryClient.prefetchQuery({
58
+ queryKey: listQuery.queryKey,
59
+ queryFn: () => {
60
+ throw errToStore;
61
+ },
62
+ retry: false
63
+ });
37
64
  }
38
65
  if (hooks?.onLoadError) {
39
66
  await hooks.onLoadError(error, context);
@@ -45,7 +72,7 @@ function createModerationLoader(config) {
45
72
  function createUserCommentsLoader(config) {
46
73
  return async () => {
47
74
  if (typeof window === "undefined") {
48
- const { apiBasePath, apiBaseURL, headers, hooks } = config;
75
+ const { queryClient, apiBasePath, apiBaseURL, headers, hooks } = config;
49
76
  const context = {
50
77
  path: "/comments",
51
78
  isSSR: true,
@@ -53,15 +80,48 @@ function createUserCommentsLoader(config) {
53
80
  apiBasePath,
54
81
  headers
55
82
  };
83
+ const client$1 = client.createApiClient({
84
+ baseURL: apiBaseURL,
85
+ basePath: apiBasePath
86
+ });
87
+ const queries = plugins_comments_queryKeys.createCommentsQueryKeys(client$1, headers);
88
+ const getUserListQuery = (currentUserId) => queries.comments.list({
89
+ authorId: currentUserId,
90
+ sort: "desc",
91
+ limit: 20,
92
+ offset: 0
93
+ });
56
94
  try {
57
95
  if (hooks?.beforeLoadUserComments) {
58
96
  await hooks.beforeLoadUserComments(context);
59
97
  }
98
+ const currentUserId = typeof context.currentUserId === "string" ? context.currentUserId : void 0;
99
+ if (currentUserId) {
100
+ const listQuery = getUserListQuery(currentUserId);
101
+ await queryClient.prefetchQuery(listQuery);
102
+ const queryState = queryClient.getQueryState(listQuery.queryKey);
103
+ if (queryState?.error && hooks?.onLoadError) {
104
+ const error = queryState.error instanceof Error ? queryState.error : new Error(String(queryState.error));
105
+ await hooks.onLoadError(error, context);
106
+ }
107
+ }
60
108
  } catch (error) {
61
109
  if (client.isConnectionError(error)) {
62
110
  console.warn(
63
111
  "[btst/comments] route.loader() failed \u2014 no server running at build time."
64
112
  );
113
+ } else {
114
+ const currentUserId = typeof context.currentUserId === "string" ? context.currentUserId : void 0;
115
+ if (currentUserId) {
116
+ const errToStore = utils.createSanitizedSSRLoaderError();
117
+ await queryClient.prefetchQuery({
118
+ queryKey: getUserListQuery(currentUserId).queryKey,
119
+ queryFn: () => {
120
+ throw errToStore;
121
+ },
122
+ retry: false
123
+ });
124
+ }
65
125
  }
66
126
  if (hooks?.onLoadError) {
67
127
  await hooks.onLoadError(error, context);