Skip to content

Commit eb3e677

Browse files
authored
chore: various playground fixes (#12291)
1 parent 2f1d2d5 commit eb3e677

File tree

9 files changed

+29
-25
lines changed

9 files changed

+29
-25
lines changed
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
import { mount, hydrate, unmount } from 'svelte';
2-
import App from './App.svelte';
2+
import App from './src/main.svelte';
33

44
const root = document.getElementById('root')!;
55
const render = root.firstChild?.nextSibling ? hydrate : mount;
66

77
const component = render(App, {
88
target: document.getElementById('root')!
99
});
10+
1011
// @ts-ignore
1112
window.unmount = () => unmount(component);
12-

playgrounds/demo/server.js renamed to playgrounds/demo/demo-server.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ async function createServer() {
3232

3333
const template = fs.readFileSync(path.resolve(__dirname, 'index.html'), 'utf-8');
3434
const transformed_template = await vite.transformIndexHtml(req.originalUrl, template);
35-
const { body: appHtml, head: headHtml } = await vite.ssrLoadModule('./src/entry-server.ts');
35+
const { render } = await vite.ssrLoadModule('svelte/server');
36+
const { default: App } = await vite.ssrLoadModule('./src/main.svelte');
37+
const { head, body } = render(App);
3638

3739
const html = transformed_template
38-
.replace(`<!--ssr-html-->`, appHtml)
39-
.replace(`<!--ssr-head-->`, headHtml);
40+
.replace(`<!--ssr-head-->`, head)
41+
.replace(`<!--ssr-body-->`, body);
4042

4143
res.writeHead(200, { 'Content-Type': 'text/html' }).end(html);
4244
});

playgrounds/demo/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
</head>
88
<body>
99
<noscript>You need to enable JavaScript to run this app.</noscript>
10-
<div id="root"><!--ssr-html--></div>
11-
<script type="module" src="/src/entry-client.ts"></script>
10+
<div id="root"><!--ssr-body--></div>
11+
<script type="module" src="/demo-client.ts"></script>
1212
</body>
1313
</html>

playgrounds/demo/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
"scripts": {
77
"prepare": "node scripts/create-app-svelte.js",
88
"dev": "vite --host",
9-
"ssr": "node ./server.js",
10-
"build": "vite build --outDir dist/client && vite build --outDir dist/server --ssr src/entry-server.ts",
9+
"ssr": "node ./demo-server.js",
10+
"build": "vite build --outDir dist/client && vite build --outDir dist/server --ssr demo-server.ts",
1111
"prod": "npm run build && node dist",
1212
"preview": "vite preview"
1313
},

playgrounds/demo/scripts/App.template.svelte

Lines changed: 0 additions & 8 deletions
This file was deleted.
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
import fs from 'node:fs';
2-
const destination = new URL('../src/App.svelte', import.meta.url);
2+
3+
const destination = new URL('../src/main.svelte', import.meta.url);
4+
35
if (!fs.existsSync(destination)) {
4-
const template = new URL('./App.template.svelte', import.meta.url);
6+
const template = new URL('./main.template.svelte', import.meta.url);
7+
8+
try {
9+
fs.mkdirSync(new URL('../src', import.meta.url));
10+
} catch {}
11+
512
fs.writeFileSync(destination, fs.readFileSync(template, 'utf-8'), 'utf-8');
613
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script lang="ts">
2+
function openInEditor() {
3+
fetch('./__open-in-editor?file=src/main.svelte');
4+
}
5+
</script>
6+
7+
<h1>Demo App</h1>
8+
<button class="open-in-editor" on:click={openInEditor}>edit main.svelte</button>

playgrounds/demo/src/entry-server.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

playgrounds/demo/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@
1313
"allowJs": true,
1414
"checkJs": true
1515
},
16-
"include": ["./src"]
16+
"include": ["./src", "demo-client.ts", "demo-server.ts"]
1717
}

0 commit comments

Comments
 (0)