Skip to content

Commit

Permalink
Add proxy for requireAsync that is instantly available
Browse files Browse the repository at this point in the history
  • Loading branch information
RumovZ committed May 18, 2024
1 parent 35f0b7d commit b7728f0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
17 changes: 17 additions & 0 deletions ts/lib/tslib/runtime-require-proxy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html

// Proxy for requireAsync in runtime-require.ts that is instantly available and
// delegates to the original function once available.
function requireAsyncProxy(name: string): Promise<Record<string, unknown>> {
return new Promise((resolve) => {
const intervalId = setInterval(() => {
if (globalThis.requireAsync !== requireAsyncProxy) {
clearInterval(intervalId);
globalThis.requireAsync(name).then(resolve);
}
}, 50);
});
}

Object.assign(globalThis, { requireAsync: requireAsyncProxy });
21 changes: 11 additions & 10 deletions ts/src/app.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<!doctype html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
<head>
<meta charset="utf-8" />
<link rel="icon" href="%sveltekit.assets%/favicon.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script type="module" src="/lib/tslib/runtime-require-proxy.ts"></script>
%sveltekit.head%
</head>
<body data-sveltekit-preload-data="hover">
<div style="display: contents">%sveltekit.body%</div>
</body>
</html>

0 comments on commit b7728f0

Please sign in to comment.