Skip to content

Commit 1719007

Browse files
authored
Merge pull request #7927 from QwikDev/fix-repl
fix(repl): bundling issue with ssr worker
2 parents 166f461 + dbc6703 commit 1719007

File tree

4 files changed

+19
-10
lines changed

4 files changed

+19
-10
lines changed

packages/docs/global.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,8 @@ declare module '*?raw-source' {
33
const url: string;
44
export default url;
55
}
6+
7+
declare module '*?compiled-string' {
8+
const str: string;
9+
export default str;
10+
}

packages/docs/src/repl/bundler/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ import type { ReplInputOptions, ReplResult } from '../types';
44
import { getDeps } from './bundled';
55
import type { InitMessage, BundleMessage, OutgoingMessage } from './bundler-worker';
66

7+
import ssrWorkerStringPre from './repl-ssr-worker?compiled-string';
8+
import listenerScript from './client-events-listener?compiled-string';
9+
10+
export const ssrWorkerString = ssrWorkerStringPre
11+
.replace(/globalThis\.DO_NOT_TOUCH_IMPORT/g, 'import')
12+
.replace('globalThis.LISTENER_SCRIPT', JSON.stringify(listenerScript));
13+
714
const bundlers = new Map<string, Bundler>();
815

916
class Bundler {

packages/docs/src/repl/bundler/repl-ssr-worker.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
// SSR Worker - handles server-side rendering execution
22
// MUST be served from /repl/ so that its imports are intercepted by the REPL service worker
33
import type { QwikManifest } from '@builder.io/qwik/optimizer';
4-
// @ts-expect-error
5-
import listenerScript from './client-events-listener?compiled-string';
64

75
// Worker message types
86
interface MessageBase {
@@ -67,8 +65,8 @@ self.onmessage = async (e: MessageEvent<IncomingMessage>) => {
6765
async function executeSSR(message: InitSSRMessage): Promise<{ html: string; events: any[] }> {
6866
const { baseUrl, manifest, entry } = message;
6967

70-
// @ts-expect-error - we prevent Vite from touching this import and replace it later
71-
const module = await DO_NOT_TOUCH_IMPORT(`/repl/${replId}-ssr/${entry}`);
68+
// We prevent Vite from touching this import() and replace it after bundling
69+
const module = await (globalThis as any).DO_NOT_TOUCH_IMPORT(`/repl/${replId}-ssr/${entry}`);
7270
const server = module.default;
7371

7472
const render = typeof server === 'function' ? server : server?.render;
@@ -103,7 +101,10 @@ async function executeSSR(message: InitSSRMessage): Promise<{ html: string; even
103101
});
104102

105103
// Inject the event listener script
106-
ssrResult.html = ssrResult.html.replace('</body>', `<script>${listenerScript}</script></body>`);
104+
ssrResult.html = ssrResult.html.replace(
105+
'</body>',
106+
`<script>${(globalThis as any).LISTENER_SCRIPT}</script></body>`
107+
);
107108

108109
// Restore console methods
109110
console.log = orig.log;

packages/docs/src/repl/ui/repl-instance.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/** Maintains the state for a REPL instance */
22

33
import { isServer, unwrapStore } from '@builder.io/qwik';
4-
import { getBundler } from '../bundler';
4+
import { getBundler, ssrWorkerString } from '../bundler';
55
import { registerReplSW } from '../register-repl-sw';
66
import type { RequestMessage, ResponseMessage } from '../repl-sw';
77
import type { ReplAppInput, ReplResult, ReplStore } from '../types';
@@ -10,10 +10,6 @@ import type {
1010
InitSSRMessage,
1111
OutgoingMessage as SSROutgoingMessage,
1212
} from '../bundler/repl-ssr-worker';
13-
// @ts-expect-error - we don't have types for this yet
14-
import ssrWorkerStringPre from '../bundler/repl-ssr-worker?compiled-string';
15-
16-
const ssrWorkerString = ssrWorkerStringPre.replace(/DO_NOT_TOUCH_IMPORT/g, 'import');
1713

1814
let channel: BroadcastChannel;
1915
let registered = false;

0 commit comments

Comments
 (0)