@qwik.dev/router 2.0.0-alpha.9 → 2.0.0-beta.2

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 (49) hide show
  1. package/README.md +1 -1
  2. package/lib/adapters/azure-swa/vite/index.cjs +3 -3
  3. package/lib/adapters/azure-swa/vite/index.d.ts +13 -13
  4. package/lib/adapters/bun-server/vite/index.cjs +3 -3
  5. package/lib/adapters/bun-server/vite/index.d.ts +14 -14
  6. package/lib/adapters/cloud-run/vite/index.cjs +3 -3
  7. package/lib/adapters/cloud-run/vite/index.d.ts +13 -13
  8. package/lib/adapters/cloudflare-pages/vite/index.cjs +3 -3
  9. package/lib/adapters/cloudflare-pages/vite/index.d.ts +27 -27
  10. package/lib/adapters/deno-server/vite/index.cjs +3 -3
  11. package/lib/adapters/deno-server/vite/index.d.ts +14 -14
  12. package/lib/adapters/netlify-edge/vite/index.cjs +3 -3
  13. package/lib/adapters/netlify-edge/vite/index.d.ts +44 -44
  14. package/lib/adapters/node-server/vite/index.cjs +3 -3
  15. package/lib/adapters/node-server/vite/index.d.ts +14 -14
  16. package/lib/adapters/shared/vite/index.cjs +10 -3
  17. package/lib/adapters/shared/vite/index.d.ts +114 -114
  18. package/lib/adapters/shared/vite/index.mjs +7 -0
  19. package/lib/adapters/static/vite/index.cjs +10 -3
  20. package/lib/adapters/static/vite/index.d.ts +10 -10
  21. package/lib/adapters/static/vite/index.mjs +7 -0
  22. package/lib/adapters/vercel-edge/vite/index.cjs +3 -3
  23. package/lib/adapters/vercel-edge/vite/index.d.ts +45 -45
  24. package/lib/index.d.ts +878 -810
  25. package/lib/index.qwik.cjs +110 -48
  26. package/lib/index.qwik.mjs +112 -50
  27. package/lib/middleware/aws-lambda/index.d.ts +48 -48
  28. package/lib/middleware/azure-swa/index.d.ts +28 -28
  29. package/lib/middleware/bun/index.d.ts +35 -35
  30. package/lib/middleware/cloudflare-pages/index.d.ts +35 -35
  31. package/lib/middleware/deno/index.d.ts +47 -47
  32. package/lib/middleware/firebase/index.d.ts +26 -26
  33. package/lib/middleware/netlify-edge/index.d.ts +27 -27
  34. package/lib/middleware/node/index.cjs +3 -3
  35. package/lib/middleware/node/index.d.ts +64 -64
  36. package/lib/middleware/request-handler/index.cjs +142 -73
  37. package/lib/middleware/request-handler/index.d.ts +710 -676
  38. package/lib/middleware/request-handler/index.mjs +138 -70
  39. package/lib/middleware/vercel-edge/index.d.ts +26 -26
  40. package/lib/service-worker.cjs +13 -263
  41. package/lib/service-worker.d.ts +15 -4
  42. package/lib/service-worker.mjs +13 -263
  43. package/lib/static/index.cjs +3 -3
  44. package/lib/static/index.d.ts +96 -96
  45. package/lib/static/node.cjs +3 -3
  46. package/lib/vite/index.cjs +209 -261
  47. package/lib/vite/index.d.ts +154 -154
  48. package/lib/vite/index.mjs +207 -259
  49. package/package.json +7 -7
@@ -1,267 +1,17 @@
1
1
  'use strict';
2
2
 
3
- const getCacheToDelete = (appBundles, cachedUrls) => cachedUrls.filter((url) => !appBundles.some((appBundle) => url.endsWith(appBundle[0])));
4
- const useCache = (request, response) => !!response && !hasNoCacheHeader(response);
5
- const hasNoCacheHeader = (r) => {
6
- const cacheControl = r.headers.get('Cache-Control') || '';
7
- return cacheControl.includes('no-cache') || cacheControl.includes('max-age=0');
8
- };
9
- const isAppBundleRequest = (appBundles, requestPathname) => appBundles.some((b) => requestPathname.endsWith('/' + b[0]));
10
- const getAppBundleByName = (appBundles, appBundleName) => appBundles.find((b) => b[0] === appBundleName);
11
- const getAppBundlesNamesFromIds = (appBundles, bundleIds) => bundleIds.map((bundleId) => (appBundles[bundleId] ? appBundles[bundleId][0] : null));
12
- const resolveSymbols = (appSymbols, symbolsHashes) => symbolsHashes.map((s) => appSymbols.get(s)).filter((s) => s != null);
13
- const computeAppSymbols = (appBundles) => {
14
- const appSymbols = new Map();
15
- for (const bundle of appBundles) {
16
- const hashes = bundle[2];
17
- if (hashes) {
18
- for (const hash of hashes) {
19
- appSymbols.set(hash, bundle[0]);
20
- }
21
- }
22
- }
23
- return appSymbols;
24
- };
25
-
26
- const cachedFetch = (cache, fetch, awaitingRequests, request) => new Promise((promiseResolve, promiseReject) => {
27
- const url = request.url;
28
- const awaitingRequestResolves = awaitingRequests.get(url);
29
- if (awaitingRequestResolves) {
30
- // there's already an active request happening
31
- // don't start a new request
32
- awaitingRequestResolves.push([promiseResolve, promiseReject]);
33
- }
34
- else {
35
- // there isn't already an active request for this url
36
- // start a new request
37
- const resolve = (response) => {
38
- // the response has been resolved
39
- const resolves = awaitingRequests.get(url);
40
- if (resolves) {
41
- awaitingRequests.delete(url);
42
- // loop through each of the active requests
43
- for (const [awaitingResolve] of resolves) {
44
- // clone a new response for each of the active requests
45
- awaitingResolve(response.clone());
46
- }
47
- }
48
- else {
49
- // somehow the array of awaiting requests doesn't exist
50
- promiseResolve(response.clone());
51
- }
52
- };
53
- const reject = (msg) => {
54
- const resolves = awaitingRequests.get(url);
55
- if (resolves) {
56
- awaitingRequests.delete(url);
57
- for (const [_, awaitingReject] of resolves) {
58
- awaitingReject(msg);
59
- }
60
- }
61
- else {
62
- promiseReject(msg);
63
- }
64
- };
65
- // create a new array of the request waiting to be resolved
66
- awaitingRequests.set(url, [[promiseResolve, promiseReject]]);
67
- cache
68
- .match(url)
69
- .then((cachedResponse) => {
70
- if (useCache(request, cachedResponse)) {
71
- // cached response found and user did not specifically send
72
- // a request header to NOT use the cache (wasn't a hard refresh)
73
- resolve(cachedResponse);
74
- }
75
- else {
76
- // no cached response found or user didn't want to use the cache
77
- // do a full network request
78
- return fetch(request).then(async (networkResponse) => {
79
- if (networkResponse.ok) {
80
- // network response was good, let's cache it
81
- await cache.put(url, networkResponse.clone());
82
- }
83
- resolve(networkResponse);
84
- });
85
- }
86
- })
87
- .catch((err) => {
88
- // network error, probably offline
89
- return cache.match(url).then((cachedResponse) => {
90
- if (cachedResponse) {
91
- // luckily we have a cached version, let's use it instead of an offline message
92
- resolve(cachedResponse);
93
- }
94
- else {
95
- // darn, we've got no connectivity and no cached response
96
- reject(err);
97
- }
98
- });
99
- });
100
- }
101
- });
102
-
103
- const qBuildCacheName = 'QwikBuild';
104
- const existingPrefetchUrls = new Set();
105
- const awaitingRequests = new Map();
106
- const prefetchQueue = [];
107
-
108
- const prefetchBundleNames = (appBundles, qBuildCache, fetch, baseUrl, prefetchAppBundleNames, highPriority = false) => {
109
- if (Array.isArray(prefetchAppBundleNames)) {
110
- addBundlesToPrefetchQueue(prefetchAppBundleNames, appBundles, baseUrl, highPriority);
111
- }
112
- drainQueue(qBuildCache, fetch);
113
- };
114
- function addBundlesToPrefetchQueue(bundlesToPrefetch, appBundles, baseUrl, highPriority) {
115
- for (const prefetchAppBundleName of bundlesToPrefetch) {
116
- try {
117
- const appBundle = getAppBundleByName(appBundles, prefetchAppBundleName);
118
- if (appBundle) {
119
- const importedBundleNames = getAppBundlesNamesFromIds(appBundles, appBundle[1]);
120
- const url = new URL(prefetchAppBundleName, baseUrl).href;
121
- const queueIndex = prefetchQueue.indexOf(url);
122
- if (queueIndex > -1) {
123
- // already in the queue
124
- if (highPriority) {
125
- // move to the front of the queue
126
- prefetchQueue.splice(queueIndex, 1);
127
- prefetchQueue.unshift(url);
128
- }
129
- }
130
- else {
131
- if (highPriority) {
132
- // add to the front of the queue
133
- prefetchQueue.unshift(url);
134
- }
135
- else {
136
- // add to the end of the queue
137
- prefetchQueue.push(url);
138
- }
139
- addBundlesToPrefetchQueue(importedBundleNames, appBundles, baseUrl, highPriority);
140
- }
141
- }
142
- }
143
- catch (e) {
144
- console.error(e);
145
- }
146
- }
147
- }
148
- function drainQueue(qBuildCache, fetch) {
149
- // do not prefetch more than 6 requests at a time to ensure
150
- // the browser is able to handle a user request as soon as possible
151
- while (prefetchQueue.length > 0 && awaitingRequests.size < 6) {
152
- const url = prefetchQueue.shift();
153
- if (!existingPrefetchUrls.has(url)) {
154
- const request = new Request(url);
155
- existingPrefetchUrls.add(url);
156
- cachedFetch(qBuildCache, fetch, awaitingRequests, request)
157
- .catch(() => {
158
- existingPrefetchUrls.delete(url);
159
- })
160
- .finally(() => drainQueue(qBuildCache, fetch));
161
- }
162
- }
163
- }
164
- const prefetchLinkBundles = (appBundles, libraryBundleIds, linkBundles, qBuildCache, fetch, baseUrl, linkPathnames) => {
165
- try {
166
- prefetchBundleNames(appBundles, qBuildCache, fetch, baseUrl, getAppBundlesNamesFromIds(appBundles, libraryBundleIds));
167
- }
168
- catch (e) {
169
- console.error(e);
170
- }
171
- for (const linkPathname of linkPathnames) {
172
- try {
173
- for (const linkBundle of linkBundles) {
174
- const [route, linkBundleIds] = linkBundle;
175
- console;
176
- if (route.test(linkPathname)) {
177
- prefetchBundleNames(appBundles, qBuildCache, fetch, baseUrl, getAppBundlesNamesFromIds(appBundles, linkBundleIds));
178
- break;
179
- }
180
- }
181
- }
182
- catch (e) {
183
- console.error(e);
184
- }
185
- }
186
- };
187
- const prefetchWaterfall = (appBundles, qBuildCache, fetch, requestedBuildUrl) => {
188
- try {
189
- const { baseUrl, requestedBundleName } = splitUrlToBaseAndBundle(requestedBuildUrl);
190
- prefetchBundleNames(appBundles, qBuildCache, fetch, baseUrl, [requestedBundleName], true);
191
- }
192
- catch (e) {
193
- console.error(e);
194
- }
195
- };
196
- function splitUrlToBaseAndBundle(fullUrl) {
197
- const segments = fullUrl.href.split('/');
198
- const requestedBundleName = segments[segments.length - 1];
199
- segments[segments.length - 1] = '';
200
- const baseUrl = new URL(segments.join('/'));
201
- return {
202
- baseUrl,
203
- requestedBundleName,
204
- };
205
- }
206
-
207
- const setupServiceWorkerScope = (swScope, appBundles, libraryBundleIds, linkBundles) => {
208
- const swFetch = swScope.fetch.bind(swScope);
209
- const appSymbols = computeAppSymbols(appBundles);
210
- swScope.addEventListener('activate', (event) => {
211
- (async () => {
212
- try {
213
- // Delete any other caches that are not the current SW cache name
214
- event.waitUntil(swScope.caches.keys().then((keys) => Promise.all(keys.map((key) => {
215
- if (key !== qBuildCacheName) {
216
- return caches.delete(key);
217
- }
218
- }))));
219
- // Delete old bundles
220
- const qBuildCache = await swScope.caches.open(qBuildCacheName);
221
- const cachedRequestKeys = await qBuildCache.keys();
222
- const cachedUrls = cachedRequestKeys.map((r) => r.url);
223
- const cachedRequestsToDelete = getCacheToDelete(appBundles, cachedUrls);
224
- await Promise.all(cachedRequestsToDelete.map((r) => qBuildCache.delete(r)));
225
- }
226
- catch (e) {
227
- console.error(e);
228
- }
229
- })();
230
- });
231
- swScope.addEventListener('message', async ({ data }) => {
232
- if (data.type === 'qprefetch' && typeof data.base === 'string') {
233
- const qBuildCache = await swScope.caches.open(qBuildCacheName);
234
- const baseUrl = new URL(data.base, swScope.origin);
235
- if (Array.isArray(data.links)) {
236
- prefetchLinkBundles(appBundles, libraryBundleIds, linkBundles, qBuildCache, swFetch, baseUrl, data.links);
237
- }
238
- if (Array.isArray(data.bundles)) {
239
- prefetchBundleNames(appBundles, qBuildCache, swFetch, baseUrl, data.bundles);
240
- }
241
- if (Array.isArray(data.symbols)) {
242
- prefetchBundleNames(appBundles, qBuildCache, swFetch, baseUrl, resolveSymbols(appSymbols, data.symbols));
243
- }
244
- }
245
- });
246
- swScope.addEventListener('fetch', (event) => {
247
- const request = event.request;
248
- if (request.method === 'GET') {
249
- const url = new URL(request.url);
250
- if (isAppBundleRequest(appBundles, url.pathname)) {
251
- event.respondWith(swScope.caches.open(qBuildCacheName).then((qBuildCache) => {
252
- prefetchWaterfall(appBundles, qBuildCache, swFetch, url);
253
- return cachedFetch(qBuildCache, swFetch, awaitingRequests, request);
254
- }));
255
- }
256
- }
257
- });
258
- };
259
-
260
- /** @public */
261
- const setupServiceWorker = () => {
262
- if (typeof self !== 'undefined' && typeof appBundles !== 'undefined') {
263
- setupServiceWorkerScope(self, appBundles, libraryBundleIds, linkBundles);
264
- }
265
- };
3
+ /**
4
+ * @deprecated This is no longer needed, Qwik now automatically embeds preloading logic into the
5
+ * application.
6
+ *
7
+ * If your service-worker.ts file contains no custom code, you should deploy to production until
8
+ * you're sure that all users picked up the new version, then you can remove it and also remove
9
+ * the `<ServiceWorkerRegister />` component from your `Root.tsx`.
10
+ *
11
+ * If you do have custom service worker logic, you should keep the `service-worker.ts` file and
12
+ * `<ServiceWorkerRegister />` component, but remove the `setupServiceWorker()` call.
13
+ * @public
14
+ */
15
+ const setupServiceWorker = () => { };
266
16
 
267
17
  exports.setupServiceWorker = setupServiceWorker;
@@ -1,4 +1,15 @@
1
- /** @public */
2
- export declare const setupServiceWorker: () => void;
3
-
4
- export { }
1
+ /**
2
+ * @deprecated This is no longer needed, Qwik now automatically embeds preloading logic into the
3
+ * application.
4
+ *
5
+ * If your service-worker.ts file contains no custom code, you should deploy to production until
6
+ * you're sure that all users picked up the new version, then you can remove it and also remove
7
+ * the `<ServiceWorkerRegister />` component from your `Root.tsx`.
8
+ *
9
+ * If you do have custom service worker logic, you should keep the `service-worker.ts` file and
10
+ * `<ServiceWorkerRegister />` component, but remove the `setupServiceWorker()` call.
11
+ * @public
12
+ */
13
+ export declare const setupServiceWorker: () => void;
14
+
15
+ export { }
@@ -1,265 +1,15 @@
1
- const getCacheToDelete = (appBundles, cachedUrls) => cachedUrls.filter((url) => !appBundles.some((appBundle) => url.endsWith(appBundle[0])));
2
- const useCache = (request, response) => !!response && !hasNoCacheHeader(response);
3
- const hasNoCacheHeader = (r) => {
4
- const cacheControl = r.headers.get('Cache-Control') || '';
5
- return cacheControl.includes('no-cache') || cacheControl.includes('max-age=0');
6
- };
7
- const isAppBundleRequest = (appBundles, requestPathname) => appBundles.some((b) => requestPathname.endsWith('/' + b[0]));
8
- const getAppBundleByName = (appBundles, appBundleName) => appBundles.find((b) => b[0] === appBundleName);
9
- const getAppBundlesNamesFromIds = (appBundles, bundleIds) => bundleIds.map((bundleId) => (appBundles[bundleId] ? appBundles[bundleId][0] : null));
10
- const resolveSymbols = (appSymbols, symbolsHashes) => symbolsHashes.map((s) => appSymbols.get(s)).filter((s) => s != null);
11
- const computeAppSymbols = (appBundles) => {
12
- const appSymbols = new Map();
13
- for (const bundle of appBundles) {
14
- const hashes = bundle[2];
15
- if (hashes) {
16
- for (const hash of hashes) {
17
- appSymbols.set(hash, bundle[0]);
18
- }
19
- }
20
- }
21
- return appSymbols;
22
- };
23
-
24
- const cachedFetch = (cache, fetch, awaitingRequests, request) => new Promise((promiseResolve, promiseReject) => {
25
- const url = request.url;
26
- const awaitingRequestResolves = awaitingRequests.get(url);
27
- if (awaitingRequestResolves) {
28
- // there's already an active request happening
29
- // don't start a new request
30
- awaitingRequestResolves.push([promiseResolve, promiseReject]);
31
- }
32
- else {
33
- // there isn't already an active request for this url
34
- // start a new request
35
- const resolve = (response) => {
36
- // the response has been resolved
37
- const resolves = awaitingRequests.get(url);
38
- if (resolves) {
39
- awaitingRequests.delete(url);
40
- // loop through each of the active requests
41
- for (const [awaitingResolve] of resolves) {
42
- // clone a new response for each of the active requests
43
- awaitingResolve(response.clone());
44
- }
45
- }
46
- else {
47
- // somehow the array of awaiting requests doesn't exist
48
- promiseResolve(response.clone());
49
- }
50
- };
51
- const reject = (msg) => {
52
- const resolves = awaitingRequests.get(url);
53
- if (resolves) {
54
- awaitingRequests.delete(url);
55
- for (const [_, awaitingReject] of resolves) {
56
- awaitingReject(msg);
57
- }
58
- }
59
- else {
60
- promiseReject(msg);
61
- }
62
- };
63
- // create a new array of the request waiting to be resolved
64
- awaitingRequests.set(url, [[promiseResolve, promiseReject]]);
65
- cache
66
- .match(url)
67
- .then((cachedResponse) => {
68
- if (useCache(request, cachedResponse)) {
69
- // cached response found and user did not specifically send
70
- // a request header to NOT use the cache (wasn't a hard refresh)
71
- resolve(cachedResponse);
72
- }
73
- else {
74
- // no cached response found or user didn't want to use the cache
75
- // do a full network request
76
- return fetch(request).then(async (networkResponse) => {
77
- if (networkResponse.ok) {
78
- // network response was good, let's cache it
79
- await cache.put(url, networkResponse.clone());
80
- }
81
- resolve(networkResponse);
82
- });
83
- }
84
- })
85
- .catch((err) => {
86
- // network error, probably offline
87
- return cache.match(url).then((cachedResponse) => {
88
- if (cachedResponse) {
89
- // luckily we have a cached version, let's use it instead of an offline message
90
- resolve(cachedResponse);
91
- }
92
- else {
93
- // darn, we've got no connectivity and no cached response
94
- reject(err);
95
- }
96
- });
97
- });
98
- }
99
- });
100
-
101
- const qBuildCacheName = 'QwikBuild';
102
- const existingPrefetchUrls = new Set();
103
- const awaitingRequests = new Map();
104
- const prefetchQueue = [];
105
-
106
- const prefetchBundleNames = (appBundles, qBuildCache, fetch, baseUrl, prefetchAppBundleNames, highPriority = false) => {
107
- if (Array.isArray(prefetchAppBundleNames)) {
108
- addBundlesToPrefetchQueue(prefetchAppBundleNames, appBundles, baseUrl, highPriority);
109
- }
110
- drainQueue(qBuildCache, fetch);
111
- };
112
- function addBundlesToPrefetchQueue(bundlesToPrefetch, appBundles, baseUrl, highPriority) {
113
- for (const prefetchAppBundleName of bundlesToPrefetch) {
114
- try {
115
- const appBundle = getAppBundleByName(appBundles, prefetchAppBundleName);
116
- if (appBundle) {
117
- const importedBundleNames = getAppBundlesNamesFromIds(appBundles, appBundle[1]);
118
- const url = new URL(prefetchAppBundleName, baseUrl).href;
119
- const queueIndex = prefetchQueue.indexOf(url);
120
- if (queueIndex > -1) {
121
- // already in the queue
122
- if (highPriority) {
123
- // move to the front of the queue
124
- prefetchQueue.splice(queueIndex, 1);
125
- prefetchQueue.unshift(url);
126
- }
127
- }
128
- else {
129
- if (highPriority) {
130
- // add to the front of the queue
131
- prefetchQueue.unshift(url);
132
- }
133
- else {
134
- // add to the end of the queue
135
- prefetchQueue.push(url);
136
- }
137
- addBundlesToPrefetchQueue(importedBundleNames, appBundles, baseUrl, highPriority);
138
- }
139
- }
140
- }
141
- catch (e) {
142
- console.error(e);
143
- }
144
- }
145
- }
146
- function drainQueue(qBuildCache, fetch) {
147
- // do not prefetch more than 6 requests at a time to ensure
148
- // the browser is able to handle a user request as soon as possible
149
- while (prefetchQueue.length > 0 && awaitingRequests.size < 6) {
150
- const url = prefetchQueue.shift();
151
- if (!existingPrefetchUrls.has(url)) {
152
- const request = new Request(url);
153
- existingPrefetchUrls.add(url);
154
- cachedFetch(qBuildCache, fetch, awaitingRequests, request)
155
- .catch(() => {
156
- existingPrefetchUrls.delete(url);
157
- })
158
- .finally(() => drainQueue(qBuildCache, fetch));
159
- }
160
- }
161
- }
162
- const prefetchLinkBundles = (appBundles, libraryBundleIds, linkBundles, qBuildCache, fetch, baseUrl, linkPathnames) => {
163
- try {
164
- prefetchBundleNames(appBundles, qBuildCache, fetch, baseUrl, getAppBundlesNamesFromIds(appBundles, libraryBundleIds));
165
- }
166
- catch (e) {
167
- console.error(e);
168
- }
169
- for (const linkPathname of linkPathnames) {
170
- try {
171
- for (const linkBundle of linkBundles) {
172
- const [route, linkBundleIds] = linkBundle;
173
- console;
174
- if (route.test(linkPathname)) {
175
- prefetchBundleNames(appBundles, qBuildCache, fetch, baseUrl, getAppBundlesNamesFromIds(appBundles, linkBundleIds));
176
- break;
177
- }
178
- }
179
- }
180
- catch (e) {
181
- console.error(e);
182
- }
183
- }
184
- };
185
- const prefetchWaterfall = (appBundles, qBuildCache, fetch, requestedBuildUrl) => {
186
- try {
187
- const { baseUrl, requestedBundleName } = splitUrlToBaseAndBundle(requestedBuildUrl);
188
- prefetchBundleNames(appBundles, qBuildCache, fetch, baseUrl, [requestedBundleName], true);
189
- }
190
- catch (e) {
191
- console.error(e);
192
- }
193
- };
194
- function splitUrlToBaseAndBundle(fullUrl) {
195
- const segments = fullUrl.href.split('/');
196
- const requestedBundleName = segments[segments.length - 1];
197
- segments[segments.length - 1] = '';
198
- const baseUrl = new URL(segments.join('/'));
199
- return {
200
- baseUrl,
201
- requestedBundleName,
202
- };
203
- }
204
-
205
- const setupServiceWorkerScope = (swScope, appBundles, libraryBundleIds, linkBundles) => {
206
- const swFetch = swScope.fetch.bind(swScope);
207
- const appSymbols = computeAppSymbols(appBundles);
208
- swScope.addEventListener('activate', (event) => {
209
- (async () => {
210
- try {
211
- // Delete any other caches that are not the current SW cache name
212
- event.waitUntil(swScope.caches.keys().then((keys) => Promise.all(keys.map((key) => {
213
- if (key !== qBuildCacheName) {
214
- return caches.delete(key);
215
- }
216
- }))));
217
- // Delete old bundles
218
- const qBuildCache = await swScope.caches.open(qBuildCacheName);
219
- const cachedRequestKeys = await qBuildCache.keys();
220
- const cachedUrls = cachedRequestKeys.map((r) => r.url);
221
- const cachedRequestsToDelete = getCacheToDelete(appBundles, cachedUrls);
222
- await Promise.all(cachedRequestsToDelete.map((r) => qBuildCache.delete(r)));
223
- }
224
- catch (e) {
225
- console.error(e);
226
- }
227
- })();
228
- });
229
- swScope.addEventListener('message', async ({ data }) => {
230
- if (data.type === 'qprefetch' && typeof data.base === 'string') {
231
- const qBuildCache = await swScope.caches.open(qBuildCacheName);
232
- const baseUrl = new URL(data.base, swScope.origin);
233
- if (Array.isArray(data.links)) {
234
- prefetchLinkBundles(appBundles, libraryBundleIds, linkBundles, qBuildCache, swFetch, baseUrl, data.links);
235
- }
236
- if (Array.isArray(data.bundles)) {
237
- prefetchBundleNames(appBundles, qBuildCache, swFetch, baseUrl, data.bundles);
238
- }
239
- if (Array.isArray(data.symbols)) {
240
- prefetchBundleNames(appBundles, qBuildCache, swFetch, baseUrl, resolveSymbols(appSymbols, data.symbols));
241
- }
242
- }
243
- });
244
- swScope.addEventListener('fetch', (event) => {
245
- const request = event.request;
246
- if (request.method === 'GET') {
247
- const url = new URL(request.url);
248
- if (isAppBundleRequest(appBundles, url.pathname)) {
249
- event.respondWith(swScope.caches.open(qBuildCacheName).then((qBuildCache) => {
250
- prefetchWaterfall(appBundles, qBuildCache, swFetch, url);
251
- return cachedFetch(qBuildCache, swFetch, awaitingRequests, request);
252
- }));
253
- }
254
- }
255
- });
256
- };
257
-
258
- /** @public */
259
- const setupServiceWorker = () => {
260
- if (typeof self !== 'undefined' && typeof appBundles !== 'undefined') {
261
- setupServiceWorkerScope(self, appBundles, libraryBundleIds, linkBundles);
262
- }
263
- };
1
+ /**
2
+ * @deprecated This is no longer needed, Qwik now automatically embeds preloading logic into the
3
+ * application.
4
+ *
5
+ * If your service-worker.ts file contains no custom code, you should deploy to production until
6
+ * you're sure that all users picked up the new version, then you can remove it and also remove
7
+ * the `<ServiceWorkerRegister />` component from your `Root.tsx`.
8
+ *
9
+ * If you do have custom service worker logic, you should keep the `service-worker.ts` file and
10
+ * `<ServiceWorkerRegister />` component, but remove the `setupServiceWorker()` call.
11
+ * @public
12
+ */
13
+ const setupServiceWorker = () => { };
264
14
 
265
15
  export { setupServiceWorker };
@@ -18,11 +18,11 @@ var __copyProps = (to, from, except, desc) => {
18
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
19
 
20
20
  // packages/qwik-router/src/static/index.ts
21
- var static_exports = {};
22
- __export(static_exports, {
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
23
  generate: () => generate
24
24
  });
25
- module.exports = __toCommonJS(static_exports);
25
+ module.exports = __toCommonJS(index_exports);
26
26
  async function generate(opts) {
27
27
  const ssgPlatform = await getEntryModule();
28
28
  const result = await ssgPlatform.generate(opts);