crelte 0.2.2 → 0.3.0

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/Crelte.d.ts +49 -9
  2. package/dist/Crelte.d.ts.map +1 -1
  3. package/dist/Crelte.js +30 -10
  4. package/dist/CrelteRequest.d.ts +3 -7
  5. package/dist/CrelteRequest.d.ts.map +1 -1
  6. package/dist/CrelteRequest.js +9 -15
  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 +15 -4
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +19 -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.map +1 -1
  25. package/dist/routing/InnerRouter.js +8 -2
  26. package/dist/routing/Router.d.ts +27 -2
  27. package/dist/routing/Router.d.ts.map +1 -1
  28. package/dist/routing/Router.js +31 -1
  29. package/dist/ssr/SsrCache.d.ts.map +1 -1
  30. package/dist/ssr/SsrCache.js +6 -1
  31. package/package.json +2 -2
  32. package/src/Crelte.ts +80 -13
  33. package/src/CrelteRequest.ts +14 -23
  34. package/src/graphql/GraphQl.ts +25 -6
  35. package/src/index.ts +30 -8
  36. package/src/init/client.ts +9 -40
  37. package/src/init/server.ts +2 -13
  38. package/src/init/shared.ts +8 -9
  39. package/src/loadData/Globals.ts +76 -93
  40. package/src/routing/InnerRouter.ts +9 -2
  41. package/src/routing/Router.ts +43 -9
  42. package/src/ssr/SsrCache.ts +6 -1
package/src/Crelte.ts CHANGED
@@ -1,15 +1,65 @@
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 Globals, { Global } from './loadData/Globals.js';
6
6
  import Events from './plugins/Events.js';
7
7
  import Plugins, { Plugin } from './plugins/Plugins.js';
8
- import Router, { RouterOptions } from './routing/Router.js';
8
+ import Router from './routing/Router.js';
9
9
  import { SiteFromGraphQl } from './routing/Site.js';
10
10
  import SsrCache from './ssr/SsrCache.js';
11
11
 
12
+ export type Config = {
13
+ /**
14
+ * Preload pages on mouse over
15
+ * @default false
16
+ */
17
+ preloadOnMouseOver?: boolean;
18
+
19
+ /**
20
+ * Use view transitions
21
+ * @default false
22
+ */
23
+ viewTransition?: boolean;
24
+
25
+ /**
26
+ * Play the intro animation
27
+ * @default false
28
+ */
29
+ playIntro?: boolean;
30
+
31
+ /**
32
+ * Enable X-Craft-Site Header
33
+ * @default false
34
+ */
35
+ XCraftSiteHeader?: boolean;
36
+
37
+ // debug
38
+
39
+ /**
40
+ * Enable graphql query debugging
41
+ * @default false
42
+ */
43
+ debugGraphQl?: boolean;
44
+
45
+ /**
46
+ * Enable request and render timing measurement
47
+ * @default false
48
+ */
49
+ debugTiming?: boolean;
50
+ };
51
+
52
+ const defaultConfig: Config = {
53
+ preloadOnMouseOver: false,
54
+ viewTransition: false,
55
+ playIntro: false,
56
+ XCraftSiteHeader: false,
57
+ debugGraphQl: false,
58
+ debugTiming: false,
59
+ };
60
+
12
61
  export class CrelteBuilder {
62
+ config: Config;
13
63
  ssrCache: SsrCache;
14
64
  plugins: Plugins;
15
65
  events: Events;
@@ -18,7 +68,9 @@ export class CrelteBuilder {
18
68
  globals: Globals;
19
69
  cookies: Cookies;
20
70
 
21
- constructor() {
71
+ constructor(config: Config) {
72
+ this.config = { ...defaultConfig, ...config };
73
+
22
74
  this.ssrCache = new SsrCache();
23
75
  this.plugins = new Plugins();
24
76
  this.events = new Events();
@@ -29,12 +81,19 @@ export class CrelteBuilder {
29
81
  : new ClientCookies();
30
82
  }
31
83
 
32
- setupGraphQl(endpoint: string, opts: GraphQlOptions = {}) {
33
- this.graphQl = new GraphQl(endpoint, this.ssrCache, opts);
84
+ setupGraphQl(endpoint: string) {
85
+ this.graphQl = new GraphQl(endpoint, this.ssrCache, {
86
+ XCraftSiteHeader: this.config.XCraftSiteHeader,
87
+ debug: this.config.debugGraphQl,
88
+ debugTiming: this.config.debugTiming,
89
+ });
34
90
  }
35
91
 
36
- setupRouter(sites: SiteFromGraphQl[], opts: RouterOptions = {}) {
37
- this.router = new Router(sites, opts);
92
+ setupRouter(sites: SiteFromGraphQl[]) {
93
+ this.router = new Router(sites, {
94
+ preloadOnMouseOver: this.config.preloadOnMouseOver,
95
+ debugTiming: this.config.debugTiming,
96
+ });
38
97
  }
39
98
 
40
99
  setupCookies(cookies: string) {
@@ -67,12 +126,20 @@ export type QueryOptions = {
67
126
  * `ignoreStatusCode` is set to `true`
68
127
  */
69
128
  status?: number;
129
+
130
+ /**
131
+ * A GraphQl Token generated in Craft
132
+ */
133
+ bearerToken?: string;
70
134
  };
71
135
 
72
136
  /**
73
137
  * 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`
138
+ * in component initialisation via `getCrelte()`
139
+ *
140
+ * Crelte is stateless, which means it is not associated with
141
+ * a specific route or site. If you need a statefull crelte
142
+ * use the function `toCrelteRequest`
76
143
  */
77
144
  export default class Crelte {
78
145
  protected _ssrCache: SsrCache;
@@ -172,8 +239,8 @@ export default class Crelte {
172
239
  * always return null. In that context you should use
173
240
  * `CrelteRequest.getGlobalAsync`
174
241
  */
175
- getGlobal<T extends GlobalData>(name: string): Global<T> | null {
176
- return this.globals.get(name) ?? null;
242
+ getGlobalStore<T = any>(name: string): Global<T> | null {
243
+ return this.globals.getStore(name) ?? null;
177
244
  }
178
245
 
179
246
  /**
@@ -191,7 +258,7 @@ export default class Crelte {
191
258
  ): Promise<unknown> {
192
259
  // this function is added as convenience
193
260
  return this.graphQl.query(query, variables, {
194
- route: this.router.route.get(),
261
+ route: this.router.route.get() ?? undefined,
195
262
  ...opts,
196
263
  });
197
264
  }
@@ -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
  /**
@@ -30,9 +26,16 @@ export default class CrelteRequest extends Crelte {
30
26
  * If you provide a route it must contain a site or you must
31
27
  * provide one,
32
28
  */
33
- static fromCrelte(inner: Crelte, req?: Route | Request): CrelteRequest {
29
+ static fromCrelte(
30
+ inner: Crelte | CrelteRequest,
31
+ req?: Route | Request,
32
+ ): CrelteRequest {
33
+ if (inner instanceof CrelteRequest && !req) return inner;
34
+
34
35
  if (!req) {
35
- req = inner.router.route.get();
36
+ req = inner.router.route.get() ?? undefined;
37
+ // this will only occur in the first loadData call
38
+ if (!req) throw new Error('router does not contain a route');
36
39
  }
37
40
 
38
41
  return new CrelteRequest(
@@ -46,6 +49,7 @@ export default class CrelteRequest extends Crelte {
46
49
  * @deprecated
47
50
  */
48
51
  get route(): Request {
52
+ console.warn('CrelteRequest.route is deprecated, use .req instead');
49
53
  return this.req;
50
54
  }
51
55
 
@@ -69,8 +73,8 @@ export default class CrelteRequest extends Crelte {
69
73
  * always return null. In that context you should use
70
74
  * `.getGlobalAsync`
71
75
  */
72
- getGlobal<T extends GlobalData>(name: string): T | null {
73
- return this.innerGlobals.get(name) ?? null;
76
+ getGlobal<T = any>(name: string): T | null {
77
+ return this.globals.get(name, this.site.id);
74
78
  }
75
79
 
76
80
  /**
@@ -80,16 +84,8 @@ export default class CrelteRequest extends Crelte {
80
84
  * This is only useful in loadGlobalData in all other cases
81
85
  * you can use `.getGlobal` which does return a Promise
82
86
  */
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);
87
+ async getGlobalAsync<T = any>(name: string): Promise<T | null> {
88
+ return this.globals.getAsync(name, this.site.id);
93
89
  }
94
90
 
95
91
  /**
@@ -111,9 +107,4 @@ export default class CrelteRequest extends Crelte {
111
107
  ...opts,
112
108
  });
113
109
  }
114
-
115
- /** @hidden */
116
- _globalDataLoaded() {
117
- this.innerGlobals = this.globals._globalsBySite(this.site.id);
118
- }
119
110
  }
@@ -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
@@ -1,12 +1,13 @@
1
1
  import { getContext, onDestroy } from 'svelte';
2
2
  import type Route from './routing/Route.js';
3
+ import type Request from './routing/Request.js';
3
4
  import type Router from './routing/Router.js';
4
5
  import type SsrCache from './ssr/SsrCache.js';
5
6
  import type Site from './routing/Site.js';
6
7
  import type GraphQl from './graphql/GraphQl.js';
7
- import Crelte, { type QueryOptions } from './Crelte.js';
8
+ import Crelte, { type QueryOptions, type Config } from './Crelte.js';
8
9
  import CrelteRequest from './CrelteRequest.js';
9
- import type { Global, GlobalData } from './loadData/Globals.js';
10
+ import type { Global } from './loadData/Globals.js';
10
11
  import type { Cookies } from './cookies/index.js';
11
12
  import type { Readable } from 'crelte-std/stores';
12
13
  import {
@@ -19,6 +20,7 @@ import {
19
20
  export {
20
21
  Crelte,
21
22
  CrelteRequest,
23
+ type Config,
22
24
  type QueryOptions,
23
25
  type LoadData,
24
26
  type LoadDataFn,
@@ -73,7 +75,10 @@ export function getGraphQl(): GraphQl {
73
75
  * This only works during component initialisation.
74
76
  */
75
77
  export function getRoute(): Readable<Route> {
76
- return getRouter().route;
78
+ // the route will never be null because it is only null in the
79
+ // first loadData call and that happens before any component
80
+ // initialisation
81
+ return getRouter().route as Readable<Route>;
77
82
  }
78
83
 
79
84
  /**
@@ -83,7 +88,10 @@ export function getRoute(): Readable<Route> {
83
88
  * This only works during component initialisation.
84
89
  */
85
90
  export function getSite(): Readable<Site> {
86
- return getRouter().site;
91
+ // the site will never be null because it is only null in the
92
+ // first loadData call and that happens before any component
93
+ // initialisation
94
+ return getRouter().site as Readable<Site>;
87
95
  }
88
96
 
89
97
  /**
@@ -127,10 +135,8 @@ export function getLoadingProgress(): Readable<number> {
127
135
  * ## Note
128
136
  * This only works during component initialisation.
129
137
  */
130
- export function getGlobal<T extends GlobalData>(
131
- name: string,
132
- ): Global<T> | null {
133
- return getCrelte().globals.get(name) ?? null;
138
+ export function getGlobal<T = any>(name: string): Global<T> | null {
139
+ return getCrelte().globals.getStore(name);
134
140
  }
135
141
 
136
142
  /**
@@ -143,6 +149,22 @@ export function getCookies(): Cookies {
143
149
  return getCrelte().cookies;
144
150
  }
145
151
 
152
+ /**
153
+ * A function to make sure you have a CrelteRequest
154
+ */
155
+ export function toCrelteRequest(
156
+ crelte: Crelte | CrelteRequest,
157
+ req?: Route | Request,
158
+ ): CrelteRequest {
159
+ return CrelteRequest.fromCrelte(crelte, req);
160
+ }
161
+
162
+ /**
163
+ * Listen for route changes
164
+ *
165
+ * ## Note
166
+ * This only works during component initialisation.
167
+ */
146
168
  export function onRoute(fn: (route: Route, crelte: Crelte) => void) {
147
169
  const crelte = getCrelte();
148
170
  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;