crelte 0.2.2 → 0.3.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 (55) hide show
  1. package/dist/Crelte.d.ts +61 -9
  2. package/dist/Crelte.d.ts.map +1 -1
  3. package/dist/Crelte.js +42 -10
  4. package/dist/CrelteRequest.d.ts +3 -11
  5. package/dist/CrelteRequest.d.ts.map +1 -1
  6. package/dist/CrelteRequest.js +9 -19
  7. package/dist/graphql/GraphQl.d.ts +7 -0
  8. package/dist/graphql/GraphQl.d.ts.map +1 -1
  9. package/dist/graphql/GraphQl.js +16 -3
  10. package/dist/index.d.ts +10 -4
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +13 -1
  13. package/dist/init/client.d.ts +0 -19
  14. package/dist/init/client.d.ts.map +1 -1
  15. package/dist/init/client.js +9 -12
  16. package/dist/init/server.d.ts +0 -4
  17. package/dist/init/server.d.ts.map +1 -1
  18. package/dist/init/server.js +2 -5
  19. package/dist/init/shared.d.ts.map +1 -1
  20. package/dist/init/shared.js +8 -8
  21. package/dist/loadData/Globals.d.ts +15 -31
  22. package/dist/loadData/Globals.d.ts.map +1 -1
  23. package/dist/loadData/Globals.js +65 -72
  24. package/dist/routing/InnerRouter.d.ts +1 -10
  25. package/dist/routing/InnerRouter.d.ts.map +1 -1
  26. package/dist/routing/InnerRouter.js +28 -23
  27. package/dist/routing/Request.d.ts +2 -0
  28. package/dist/routing/Request.d.ts.map +1 -1
  29. package/dist/routing/Request.js +9 -0
  30. package/dist/routing/Route.d.ts +56 -1
  31. package/dist/routing/Route.d.ts.map +1 -1
  32. package/dist/routing/Route.js +85 -2
  33. package/dist/routing/Router.d.ts +29 -4
  34. package/dist/routing/Router.d.ts.map +1 -1
  35. package/dist/routing/Router.js +39 -12
  36. package/dist/ssr/SsrCache.d.ts.map +1 -1
  37. package/dist/ssr/SsrCache.js +6 -1
  38. package/dist/utils.d.ts +2 -0
  39. package/dist/utils.d.ts.map +1 -0
  40. package/dist/utils.js +8 -0
  41. package/package.json +2 -2
  42. package/src/Crelte.ts +95 -13
  43. package/src/CrelteRequest.ts +14 -27
  44. package/src/graphql/GraphQl.ts +25 -6
  45. package/src/index.ts +19 -8
  46. package/src/init/client.ts +9 -40
  47. package/src/init/server.ts +2 -13
  48. package/src/init/shared.ts +8 -9
  49. package/src/loadData/Globals.ts +76 -93
  50. package/src/routing/InnerRouter.ts +38 -32
  51. package/src/routing/Request.ts +11 -0
  52. package/src/routing/Route.ts +93 -2
  53. package/src/routing/Router.ts +51 -20
  54. package/src/ssr/SsrCache.ts +6 -1
  55. package/src/utils.ts +10 -0
package/src/Crelte.ts CHANGED
@@ -1,15 +1,68 @@
1
1
  import ClientCookies from './cookies/ClientCookies.js';
2
2
  import { Cookies } from './cookies/index.js';
3
3
  import ServerCookies from './cookies/ServerCookies.js';
4
- import GraphQl, { GraphQlOptions, GraphQlQuery } from './graphql/GraphQl.js';
5
- import Globals, { Global, GlobalData } from './loadData/Globals.js';
4
+ import GraphQl, { GraphQlQuery } from './graphql/GraphQl.js';
5
+ import { CrelteRequest } from './index.js';
6
+ import Globals, { Global } from './loadData/Globals.js';
6
7
  import Events from './plugins/Events.js';
7
8
  import Plugins, { Plugin } from './plugins/Plugins.js';
8
- import Router, { RouterOptions } from './routing/Router.js';
9
+ import type Route from './routing/Route.js';
10
+ import type Request from './routing/Request.js';
11
+ import Router from './routing/Router.js';
9
12
  import { SiteFromGraphQl } from './routing/Site.js';
10
13
  import SsrCache from './ssr/SsrCache.js';
11
14
 
15
+ export type Config = {
16
+ /**
17
+ * Preload pages on mouse over
18
+ * @default false
19
+ */
20
+ preloadOnMouseOver?: boolean;
21
+
22
+ /**
23
+ * Use view transitions
24
+ * @default false
25
+ */
26
+ viewTransition?: boolean;
27
+
28
+ /**
29
+ * Play the intro animation
30
+ * @default false
31
+ */
32
+ playIntro?: boolean;
33
+
34
+ /**
35
+ * Enable X-Craft-Site Header
36
+ * @default false
37
+ */
38
+ XCraftSiteHeader?: boolean;
39
+
40
+ // debug
41
+
42
+ /**
43
+ * Enable graphql query debugging
44
+ * @default false
45
+ */
46
+ debugGraphQl?: boolean;
47
+
48
+ /**
49
+ * Enable request and render timing measurement
50
+ * @default false
51
+ */
52
+ debugTiming?: boolean;
53
+ };
54
+
55
+ const defaultConfig: Config = {
56
+ preloadOnMouseOver: false,
57
+ viewTransition: false,
58
+ playIntro: false,
59
+ XCraftSiteHeader: false,
60
+ debugGraphQl: false,
61
+ debugTiming: false,
62
+ };
63
+
12
64
  export class CrelteBuilder {
65
+ config: Config;
13
66
  ssrCache: SsrCache;
14
67
  plugins: Plugins;
15
68
  events: Events;
@@ -18,7 +71,9 @@ export class CrelteBuilder {
18
71
  globals: Globals;
19
72
  cookies: Cookies;
20
73
 
21
- constructor() {
74
+ constructor(config: Config) {
75
+ this.config = { ...defaultConfig, ...config };
76
+
22
77
  this.ssrCache = new SsrCache();
23
78
  this.plugins = new Plugins();
24
79
  this.events = new Events();
@@ -29,12 +84,19 @@ export class CrelteBuilder {
29
84
  : new ClientCookies();
30
85
  }
31
86
 
32
- setupGraphQl(endpoint: string, opts: GraphQlOptions = {}) {
33
- this.graphQl = new GraphQl(endpoint, this.ssrCache, opts);
87
+ setupGraphQl(endpoint: string) {
88
+ this.graphQl = new GraphQl(endpoint, this.ssrCache, {
89
+ XCraftSiteHeader: this.config.XCraftSiteHeader,
90
+ debug: this.config.debugGraphQl,
91
+ debugTiming: this.config.debugTiming,
92
+ });
34
93
  }
35
94
 
36
- setupRouter(sites: SiteFromGraphQl[], opts: RouterOptions = {}) {
37
- this.router = new Router(sites, opts);
95
+ setupRouter(sites: SiteFromGraphQl[]) {
96
+ this.router = new Router(sites, {
97
+ preloadOnMouseOver: this.config.preloadOnMouseOver,
98
+ debugTiming: this.config.debugTiming,
99
+ });
38
100
  }
39
101
 
40
102
  setupCookies(cookies: string) {
@@ -67,12 +129,20 @@ export type QueryOptions = {
67
129
  * `ignoreStatusCode` is set to `true`
68
130
  */
69
131
  status?: number;
132
+
133
+ /**
134
+ * A GraphQl Token generated in Craft
135
+ */
136
+ bearerToken?: string;
70
137
  };
71
138
 
72
139
  /**
73
140
  * This is the main class of Crelte and can be accessed
74
- * in component initialisation via `getCrelte()` and is the
75
- * first parameter in `loadData`
141
+ * in component initialisation via `getCrelte()`
142
+ *
143
+ * Crelte is stateless, which means it is not associated with
144
+ * a specific route or site. If you need a statefull crelte
145
+ * use the function `toCrelteRequest`
76
146
  */
77
147
  export default class Crelte {
78
148
  protected _ssrCache: SsrCache;
@@ -172,8 +242,20 @@ export default class Crelte {
172
242
  * always return null. In that context you should use
173
243
  * `CrelteRequest.getGlobalAsync`
174
244
  */
175
- getGlobal<T extends GlobalData>(name: string): Global<T> | null {
176
- return this.globals.get(name) ?? null;
245
+ getGlobalStore<T = any>(name: string): Global<T> | null {
246
+ return this.globals.getStore(name) ?? null;
247
+ }
248
+
249
+ /**
250
+ * returns a new CrelteRequest instance either with the current
251
+ * route or a provided one
252
+ *
253
+ * ## Note
254
+ * This is useful if you want to create a stateful crelte
255
+ * to use in loadData context
256
+ */
257
+ toRequest(req?: Route | Request): CrelteRequest {
258
+ return CrelteRequest.fromCrelte(this, req);
177
259
  }
178
260
 
179
261
  /**
@@ -191,7 +273,7 @@ export default class Crelte {
191
273
  ): Promise<unknown> {
192
274
  // this function is added as convenience
193
275
  return this.graphQl.query(query, variables, {
194
- route: this.router.route.get(),
276
+ route: this.router.route.get() ?? undefined,
195
277
  ...opts,
196
278
  });
197
279
  }
@@ -3,7 +3,6 @@ import { GraphQlQuery } from './graphql/GraphQl.js';
3
3
  import Site from './routing/Site.js';
4
4
  import Request from './routing/Request.js';
5
5
  import Route from './routing/Route.js';
6
- import { GlobalData } from './loadData/Globals.js';
7
6
 
8
7
  export default class CrelteRequest extends Crelte {
9
8
  /**
@@ -11,13 +10,10 @@ export default class CrelteRequest extends Crelte {
11
10
  */
12
11
  req: Request;
13
12
 
14
- private innerGlobals: Map<string, any>;
15
-
16
13
  constructor(inner: Crelte, req: Request) {
17
14
  super(inner);
18
15
 
19
16
  this.req = req;
20
- this.innerGlobals = new Map();
21
17
  }
22
18
 
23
19
  /**
@@ -25,14 +21,17 @@ export default class CrelteRequest extends Crelte {
25
21
  *
26
22
  * If you don't provide a route or request the current route
27
23
  * will be used.
28
- *
29
- * ## Note
30
- * If you provide a route it must contain a site or you must
31
- * provide one,
32
24
  */
33
- static fromCrelte(inner: Crelte, req?: Route | Request): CrelteRequest {
25
+ static fromCrelte(
26
+ inner: Crelte | CrelteRequest,
27
+ req?: Route | Request,
28
+ ): CrelteRequest {
29
+ if (inner instanceof CrelteRequest && !req) return inner;
30
+
34
31
  if (!req) {
35
- req = inner.router.route.get();
32
+ req = inner.router.route.get() ?? undefined;
33
+ // this will only occur in the first loadData call
34
+ if (!req) throw new Error('router does not contain a route');
36
35
  }
37
36
 
38
37
  return new CrelteRequest(
@@ -46,6 +45,7 @@ export default class CrelteRequest extends Crelte {
46
45
  * @deprecated
47
46
  */
48
47
  get route(): Request {
48
+ console.warn('CrelteRequest.route is deprecated, use .req instead');
49
49
  return this.req;
50
50
  }
51
51
 
@@ -69,8 +69,8 @@ export default class CrelteRequest extends Crelte {
69
69
  * always return null. In that context you should use
70
70
  * `.getGlobalAsync`
71
71
  */
72
- getGlobal<T extends GlobalData>(name: string): T | null {
73
- return this.innerGlobals.get(name) ?? null;
72
+ getGlobal<T = any>(name: string): T | null {
73
+ return this.globals.get(name, this.site.id);
74
74
  }
75
75
 
76
76
  /**
@@ -80,16 +80,8 @@ export default class CrelteRequest extends Crelte {
80
80
  * This is only useful in loadGlobalData in all other cases
81
81
  * you can use `.getGlobal` which does return a Promise
82
82
  */
83
- async getGlobalAsync<T extends GlobalData>(
84
- name: string,
85
- ): Promise<T | null> {
86
- const global = this.innerGlobals.get(name);
87
- if (global) return global;
88
-
89
- const r = await this.globals.getAsync<T>(name);
90
- if (!r) return null;
91
-
92
- return r.bySiteId(this.site.id);
83
+ async getGlobalAsync<T = any>(name: string): Promise<T | null> {
84
+ return this.globals.getAsync(name, this.site.id);
93
85
  }
94
86
 
95
87
  /**
@@ -111,9 +103,4 @@ export default class CrelteRequest extends Crelte {
111
103
  ...opts,
112
104
  });
113
105
  }
114
-
115
- /** @hidden */
116
- _globalDataLoaded() {
117
- this.innerGlobals = this.globals._globalsBySite(this.site.id);
118
- }
119
106
  }
@@ -54,6 +54,7 @@ export class GraphQlError extends Error {
54
54
  * Options for the GraphQl class
55
55
  */
56
56
  export type GraphQlOptions = {
57
+ XCraftSiteHeader?: boolean;
57
58
  debug?: boolean;
58
59
  debugTiming?: boolean;
59
60
  };
@@ -70,12 +71,15 @@ export type GraphQlOptions = {
70
71
  */
71
72
  export type GraphQlRequestOptions = {
72
73
  path?: string;
73
- // !! the route here might not contain a site even if the types
74
- // says it does. CrelteServer does not know about site
74
+ /**
75
+ * !! the route here might not contain a site even if the types
76
+ * says it does. CrelteServer does not know about site
77
+ */
75
78
  route?: Route | URL;
76
79
  ignoreStatusCode?: boolean;
77
80
  previewToken?: string;
78
81
  siteToken?: string;
82
+ bearerToken?: string;
79
83
  caching?: boolean;
80
84
  headers?: Record<string, string>;
81
85
  // will be set by the request function
@@ -93,6 +97,7 @@ export default class GraphQl {
93
97
  [(resp: unknown) => void, (error: unknown) => void][]
94
98
  >;
95
99
 
100
+ private XCraftSiteHeader: boolean;
96
101
  private loggingRequests: boolean;
97
102
  private loggingTiming: boolean;
98
103
 
@@ -108,6 +113,7 @@ export default class GraphQl {
108
113
  this.ssrCache = ssrCache;
109
114
  this.listeners = new Map();
110
115
 
116
+ this.XCraftSiteHeader = opts?.XCraftSiteHeader ?? false;
111
117
  this.loggingRequests = opts?.debug ?? false;
112
118
  this.loggingTiming = opts?.debugTiming ?? false;
113
119
  }
@@ -129,15 +135,25 @@ export default class GraphQl {
129
135
  const search =
130
136
  (opts.route as URL).searchParams ?? opts.route.search;
131
137
 
132
- // todo should variables contain siteId
133
- // or maybe gql should detect loadData and add it there
134
- // it might make export const loadData = query; easier
135
-
136
138
  if (search.has('token') && search.get('x-craft-live-preview')) {
137
139
  opts.previewToken = search.get('token')!;
138
140
  } else if (search.has('siteToken')) {
139
141
  opts.siteToken = search.get('siteToken')!;
140
142
  }
143
+
144
+ // if the siteId is not set we set it as an argument for
145
+ // convenience
146
+ if ((opts.route as Route).site) {
147
+ if (this.XCraftSiteHeader && !opts.headers?.['X-Craft-Site']) {
148
+ opts.headers = opts.headers ?? {};
149
+ opts.headers['X-Craft-Site'] =
150
+ (opts.route as Route).site.id + '';
151
+ }
152
+
153
+ if (typeof variables.siteId === 'undefined') {
154
+ variables.siteId = (opts.route as Route).site.id;
155
+ }
156
+ }
141
157
  }
142
158
 
143
159
  opts.path = query.path;
@@ -220,6 +236,9 @@ export default class GraphQl {
220
236
  const headers = opts?.headers ?? {};
221
237
  headers['Content-Type'] = 'application/json';
222
238
 
239
+ if (opts?.bearerToken)
240
+ headers['Authorization'] = 'Bearer ' + opts.bearerToken;
241
+
223
242
  if (this.loggingRequests) {
224
243
  console.log('query to ', url, variables, opts);
225
244
  headers['X-Debug'] = 'enable';
package/src/index.ts CHANGED
@@ -4,9 +4,9 @@ import type Router from './routing/Router.js';
4
4
  import type SsrCache from './ssr/SsrCache.js';
5
5
  import type Site from './routing/Site.js';
6
6
  import type GraphQl from './graphql/GraphQl.js';
7
- import Crelte, { type QueryOptions } from './Crelte.js';
7
+ import Crelte, { type QueryOptions, type Config } from './Crelte.js';
8
8
  import CrelteRequest from './CrelteRequest.js';
9
- import type { Global, GlobalData } from './loadData/Globals.js';
9
+ import type { Global } from './loadData/Globals.js';
10
10
  import type { Cookies } from './cookies/index.js';
11
11
  import type { Readable } from 'crelte-std/stores';
12
12
  import {
@@ -19,6 +19,7 @@ import {
19
19
  export {
20
20
  Crelte,
21
21
  CrelteRequest,
22
+ type Config,
22
23
  type QueryOptions,
23
24
  type LoadData,
24
25
  type LoadDataFn,
@@ -73,7 +74,10 @@ export function getGraphQl(): GraphQl {
73
74
  * This only works during component initialisation.
74
75
  */
75
76
  export function getRoute(): Readable<Route> {
76
- return getRouter().route;
77
+ // the route will never be null because it is only null in the
78
+ // first loadData call and that happens before any component
79
+ // initialisation
80
+ return getRouter().route as Readable<Route>;
77
81
  }
78
82
 
79
83
  /**
@@ -83,7 +87,10 @@ export function getRoute(): Readable<Route> {
83
87
  * This only works during component initialisation.
84
88
  */
85
89
  export function getSite(): Readable<Site> {
86
- return getRouter().site;
90
+ // the site will never be null because it is only null in the
91
+ // first loadData call and that happens before any component
92
+ // initialisation
93
+ return getRouter().site as Readable<Site>;
87
94
  }
88
95
 
89
96
  /**
@@ -127,10 +134,8 @@ export function getLoadingProgress(): Readable<number> {
127
134
  * ## Note
128
135
  * This only works during component initialisation.
129
136
  */
130
- export function getGlobal<T extends GlobalData>(
131
- name: string,
132
- ): Global<T> | null {
133
- return getCrelte().globals.get(name) ?? null;
137
+ export function getGlobal<T = any>(name: string): Global<T> | null {
138
+ return getCrelte().globals.getStore(name);
134
139
  }
135
140
 
136
141
  /**
@@ -143,6 +148,12 @@ export function getCookies(): Cookies {
143
148
  return getCrelte().cookies;
144
149
  }
145
150
 
151
+ /**
152
+ * Listen for route changes
153
+ *
154
+ * ## Note
155
+ * This only works during component initialisation.
156
+ */
146
157
  export function onRoute(fn: (route: Route, crelte: Crelte) => void) {
147
158
  const crelte = getCrelte();
148
159
  const rmListener = crelte.router.onRoute(route => {
@@ -17,40 +17,13 @@ export type MainData = {
17
17
  entryQuery: GraphQlQuery;
18
18
  /** The global query from queries/global.graphql */
19
19
  globalQuery?: GraphQlQuery;
20
-
21
- // options
22
-
23
- /**
24
- * Preload pages on mouse over
25
- * @default false
26
- */
27
- preloadOnMouseOver?: boolean;
28
-
29
- /**
30
- * Use view transitions
31
- * @default false
32
- */
33
- viewTransition?: boolean;
34
-
35
- /**
36
- * Play the intro animation
37
- * @default false
38
- */
39
- playIntro?: boolean;
40
-
41
- // debug
42
-
43
- /** Enable graphql query debugging */
44
- graphQlDebug?: boolean;
45
-
46
- /** Enable request and render timing measurement */
47
- debugTiming?: boolean;
48
20
  };
49
21
 
50
22
  const mainDataDefault = {
51
23
  preloadOnMouseOver: false,
52
24
  viewTransition: false,
53
25
  playIntro: false,
26
+ XCraftSiteHeader: false,
54
27
 
55
28
  // will be passed down to ClientRenderer
56
29
  graphQlDebug: false,
@@ -95,20 +68,15 @@ export function main(data: MainData) {
95
68
 
96
69
  // construct Crelte
97
70
 
98
- const builder = new CrelteBuilder();
71
+ const builder = new CrelteBuilder(data.app.config ?? {});
99
72
  const endpoint = builder.ssrCache.get('ENDPOINT_URL') as string;
100
- builder.setupGraphQl(endpoint, {
101
- debug: data.graphQlDebug,
102
- debugTiming: data.debugTiming,
103
- });
73
+ builder.setupGraphQl(endpoint);
104
74
 
105
75
  // on the client the cookies are always coming from document.cookie
106
76
  builder.setupCookies('');
107
77
 
108
78
  const csites = builder.ssrCache.get('crelteSites') as SiteFromGraphQl[];
109
- builder.setupRouter(csites, {
110
- preloadOnMouseOver: data.preloadOnMouseOver,
111
- });
79
+ builder.setupRouter(csites);
112
80
 
113
81
  const crelte = builder.build();
114
82
 
@@ -146,7 +114,7 @@ export function main(data: MainData) {
146
114
  props,
147
115
  hydrate: true,
148
116
  context: crelte._getContext(),
149
- intro: data.playIntro,
117
+ intro: builder.config.playIntro,
150
118
  });
151
119
  } else {
152
120
  appInstance.$set(props);
@@ -161,7 +129,8 @@ export function main(data: MainData) {
161
129
  if (!success) {
162
130
  // if this is not the first load we should reload the page
163
131
  // we don't reload everytime because this might cause a reload loop
164
- // and since the first load will probably just contain ssrCache data in almost all cases the first load will never faill
132
+ // and since the first load will probably just contain ssrCache data
133
+ // in almost all cases the first load will never faill
165
134
  if (!isFirstLoad) {
166
135
  // the load might contain a js error and we prefer the error
167
136
  // page
@@ -174,7 +143,7 @@ export function main(data: MainData) {
174
143
 
175
144
  const cr = new CrelteRequest(crelte, req);
176
145
 
177
- const startTime = data.debugTiming ? Date.now() : null;
146
+ const startTime = builder.config.debugTiming ? Date.now() : null;
178
147
  let render = async () => {
179
148
  // we should trigger the route update here
180
149
  pluginsBeforeRender(cr);
@@ -194,7 +163,7 @@ export function main(data: MainData) {
194
163
 
195
164
  // render with view Transition if enabled and not in hydration
196
165
  if (
197
- data.viewTransition &&
166
+ builder.config.viewTransition &&
198
167
  appInstance &&
199
168
  (document as any).startViewTransition
200
169
  ) {
@@ -33,14 +33,6 @@ export type MainData = {
33
33
 
34
34
  /** Server data provided by crelte-node */
35
35
  serverData: ServerData;
36
-
37
- // debug
38
-
39
- /** Enable graphql query debugging */
40
- graphQlDebug?: boolean;
41
-
42
- /** Enable request and render timing measurement */
43
- debugTiming?: boolean;
44
36
  };
45
37
 
46
38
  /**
@@ -69,7 +61,7 @@ export async function main(data: MainData): Promise<{
69
61
  html?: string;
70
62
  setCookies?: string[];
71
63
  }> {
72
- const builder = new CrelteBuilder();
64
+ const builder = new CrelteBuilder(data.app.config ?? {});
73
65
 
74
66
  // setup viteEnv
75
67
  data.serverData.viteEnv.forEach((v, k) => {
@@ -79,10 +71,7 @@ export async function main(data: MainData): Promise<{
79
71
  const endpoint = data.serverData.endpoint;
80
72
  builder.ssrCache.set('ENDPOINT_URL', endpoint);
81
73
  builder.ssrCache.set('CRAFT_WEB_URL', data.serverData.craftWeb);
82
- builder.setupGraphQl(endpoint, {
83
- debug: data.graphQlDebug,
84
- debugTiming: data.debugTiming,
85
- });
74
+ builder.setupGraphQl(endpoint);
86
75
 
87
76
  const cookies = data.serverData.cookies ?? '';
88
77
  builder.setupCookies(cookies);
@@ -79,27 +79,29 @@ export async function loadFn<D, E, T>(
79
79
  }
80
80
 
81
81
  let globalProm: Promise<any> | null = null;
82
- if (globalQuery && !cr.globals._wasLoaded()) {
82
+ if (globalQuery && !cr.globals._wasLoaded(cr.site.id)) {
83
83
  globalProm = (async () => {
84
- const res = await cr.query(globalQuery);
84
+ const res = await cr.query(globalQuery, {
85
+ siteId: cr.site.id,
86
+ });
85
87
  // we need to do this sorcery here and can't wait until all
86
88
  // globals functions are done, because some global function
87
89
  // might want to use globals, and for that the function
88
- // getOrWait exists on Globals
90
+ // getAsync exists on Globals
89
91
  cr.globals._setData(cr.site.id, res);
90
92
  return res;
91
93
  })();
92
94
  }
93
95
 
94
96
  let pageProm = null;
95
- if (cr.req.site) {
97
+ if (cr.req.siteMatches()) {
96
98
  let uri = decodeURI(cr.req.uri);
97
99
  if (uri.startsWith('/')) uri = uri.substring(1);
98
100
  if (uri === '' || uri === '/') uri = '__home__';
99
101
 
100
102
  pageProm = cr.query(entryQuery, {
101
103
  uri,
102
- siteId: cr.req.site.id,
104
+ siteId: cr.site.id,
103
105
  });
104
106
  }
105
107
 
@@ -117,15 +119,12 @@ export async function loadFn<D, E, T>(
117
119
 
118
120
  if (global) {
119
121
  cr.globals._setData(cr.site.id, global);
120
- } else if (!cr.globals._wasLoaded()) {
122
+ } else if (!cr.globals._wasLoaded(cr.site.id)) {
121
123
  // we need to set the global data to an empty object
122
124
  // so any waiters get's triggered
123
125
  cr.globals._setData(cr.site.id, {});
124
126
  }
125
127
 
126
- // allow cr to get the global data
127
- cr._globalDataLoaded();
128
-
129
128
  const entry = getEntry(page);
130
129
 
131
130
  let template;