@rsc-kit/core 0.21.0 → 0.21.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.
- package/dist/vite.js +36 -3
- package/dist/vite.js.map +1 -1
- package/package.json +1 -1
package/dist/vite.js
CHANGED
|
@@ -841,6 +841,14 @@ self.importScripts(${JSON.stringify(swExtra)})
|
|
|
841
841
|
`
|
|
842
842
|
: ""}
|
|
843
843
|
|
|
844
|
+
// How long one install-time fetch may take. An install is pending until every
|
|
845
|
+
// fetch in it settles, and a request that never answers kept the previous
|
|
846
|
+
// worker in charge for as long as it hung - so one that is late is treated
|
|
847
|
+
// like one that failed: skipped, and fetched again the first time it is used.
|
|
848
|
+
const INSTALL_FETCH_MS = 30000
|
|
849
|
+
const within = (ms, promise) =>
|
|
850
|
+
Promise.race([promise, new Promise((_, reject) => setTimeout(() => reject(new Error('no answer in ' + ms + ' ms')), ms))])
|
|
851
|
+
|
|
844
852
|
self.addEventListener('install', (event) => {
|
|
845
853
|
// The new worker takes over rather than waiting for every tab to close.
|
|
846
854
|
// Safe here because assets are content-hashed: a page already open keeps
|
|
@@ -853,7 +861,26 @@ self.addEventListener('install', (event) => {
|
|
|
853
861
|
// it is served by the host out of the prerendered directory, which this
|
|
854
862
|
// worker cannot see. Added here so it is in the cache before it is
|
|
855
863
|
// needed, which is the only moment it cannot be fetched.
|
|
856
|
-
|
|
864
|
+
//
|
|
865
|
+
// One at a time rather than cache.addAll, which rejects the whole list
|
|
866
|
+
// for one failure - and a worker whose install rejects is never
|
|
867
|
+
// installed. The worker before it then stays in charge, serving its own
|
|
868
|
+
// build's pages, for every visit until one install happens to succeed:
|
|
869
|
+
// a network blip, a quota, a file a deploy replaced mid-install, and a
|
|
870
|
+
// phone kept a worker from builds ago whose bugs had long been fixed.
|
|
871
|
+
// A file that did not arrive costs a cache entry; the update still
|
|
872
|
+
// lands. The browser checks /sw.js for itself, without the page's
|
|
873
|
+
// javascript, so an install that cannot fail is also what rescues a
|
|
874
|
+
// visitor stuck on a worker far older than this one.
|
|
875
|
+
.then((cache) =>
|
|
876
|
+
Promise.all(
|
|
877
|
+
(OFFLINE_URL ? [...PRECACHE, OFFLINE_URL] : PRECACHE).map((url) =>
|
|
878
|
+
within(INSTALL_FETCH_MS, cache.add(url)).catch((error) => {
|
|
879
|
+
console.warn('[rsc-kit] offline: ' + url + ' was not precached (' + (error && error.message || error) + '); it will be cached the first time it is fetched')
|
|
880
|
+
}),
|
|
881
|
+
),
|
|
882
|
+
).then(() => cache),
|
|
883
|
+
)
|
|
857
884
|
// And the payload each precached page boots from. A document alone is
|
|
858
885
|
// markup that never hydrates: the client fetches its payload on boot,
|
|
859
886
|
// and a precached / rendered offline and stayed inert because that
|
|
@@ -865,7 +892,7 @@ self.addEventListener('install', (event) => {
|
|
|
865
892
|
.map((url) => {
|
|
866
893
|
const warm = new Request(url, { headers: { 'X-RSC': '1' } })
|
|
867
894
|
|
|
868
|
-
return fetch(warm)
|
|
895
|
+
return within(INSTALL_FETCH_MS, fetch(warm))
|
|
869
896
|
.then((payload) => {
|
|
870
897
|
if (mayStore(payload)) return cache.put(keyFor(warm), payload)
|
|
871
898
|
|
|
@@ -6228,7 +6255,13 @@ export function rscKit(options = {}) {
|
|
|
6228
6255
|
// dependency exists once, so there is nothing to collide.
|
|
6229
6256
|
// The server does not pay for the bigger chunk the way a
|
|
6230
6257
|
// browser would: it reads from disk, once, at startup.
|
|
6231
|
-
|
|
6258
|
+
//
|
|
6259
|
+
// `codeSplitting`, rolldown's name for what was
|
|
6260
|
+
// `advancedChunks`: the old name still works and prints a
|
|
6261
|
+
// deprecation warning in every build, twice - plugin-rsc
|
|
6262
|
+
// builds this environment once to scan and once for real.
|
|
6263
|
+
// Every rolldown a Vite 8 ships with knows the new name.
|
|
6264
|
+
codeSplitting: {
|
|
6232
6265
|
groups: [{ name: "vendor", test: /[\\/]node_modules[\\/]/ }],
|
|
6233
6266
|
},
|
|
6234
6267
|
},
|