chore: update sandbox to support async SSR (#16787)

* chore: update sandbox to support async SSR

* dedupe

* fix some stuff

* fix

* bump devDependencies
pull/16070/merge
Rich Harris 19 hours ago committed by GitHub
parent 16e16da1a8
commit 88d7e05a2e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
"svelte": patch
---
chore: bump some devDependencies

@ -30,6 +30,7 @@
"@sveltejs/eslint-config": "^8.3.3", "@sveltejs/eslint-config": "^8.3.3",
"@svitejs/changesets-changelog-github-compact": "^1.1.0", "@svitejs/changesets-changelog-github-compact": "^1.1.0",
"@types/node": "^20.11.5", "@types/node": "^20.11.5",
"@types/picomatch": "^4.0.2",
"@vitest/coverage-v8": "^2.1.9", "@vitest/coverage-v8": "^2.1.9",
"eslint": "^9.9.1", "eslint": "^9.9.1",
"eslint-plugin-lube": "^0.4.3", "eslint-plugin-lube": "^0.4.3",

@ -283,11 +283,16 @@ export type DeclarationKind =
| 'var' | 'var'
| 'let' | 'let'
| 'const' | 'const'
| 'using'
| 'await using'
| 'function' | 'function'
| 'import' | 'import'
| 'param' | 'param'
| 'rest_param' | 'rest_param'
| 'synthetic'; | 'synthetic'
// TODO not yet implemented, but needed for TypeScript reasons
| 'using'
| 'await using';
export interface ExpressionMetadata { export interface ExpressionMetadata {
/** All the bindings that are referenced eagerly (not inside functions) in this expression */ /** All the bindings that are referenced eagerly (not inside functions) in this expression */

@ -364,7 +364,14 @@ export function prop(kind, key, value, computed = false) {
* @returns {ESTree.PropertyDefinition} * @returns {ESTree.PropertyDefinition}
*/ */
export function prop_def(key, value, computed = false, is_static = false) { export function prop_def(key, value, computed = false, is_static = false) {
return { type: 'PropertyDefinition', key, value, computed, static: is_static }; return {
type: 'PropertyDefinition',
decorators: [],
key,
value,
computed,
static: is_static
};
} }
/** /**
@ -565,6 +572,7 @@ function for_builder(init, test, update, body) {
export function method(kind, key, params, body, computed = false, is_static = false) { export function method(kind, key, params, body, computed = false, is_static = false) {
return { return {
type: 'MethodDefinition', type: 'MethodDefinition',
decorators: [],
key, key,
kind, kind,
value: function_builder(null, params, block(body)), value: function_builder(null, params, block(body)),
@ -610,6 +618,7 @@ function if_builder(test, consequent, alternate) {
export function import_all(as, source) { export function import_all(as, source) {
return { return {
type: 'ImportDeclaration', type: 'ImportDeclaration',
attributes: [],
source: literal(source), source: literal(source),
specifiers: [import_namespace(as)] specifiers: [import_namespace(as)]
}; };
@ -623,6 +632,7 @@ export function import_all(as, source) {
export function imports(parts, source) { export function imports(parts, source) {
return { return {
type: 'ImportDeclaration', type: 'ImportDeclaration',
attributes: [],
source: literal(source), source: literal(source),
specifiers: parts.map((p) => ({ specifiers: parts.map((p) => ({
type: 'ImportSpecifier', type: 'ImportSpecifier',

@ -259,7 +259,8 @@
"kind": "let" "kind": "let"
}, },
"specifiers": [], "specifiers": [],
"source": null "source": null,
"attributes": []
} }
], ],
"sourceType": "module" "sourceType": "module"

@ -169,7 +169,8 @@
"kind": "const" "kind": "const"
}, },
"specifiers": [], "specifiers": [],
"source": null "source": null,
"attributes": []
} }
], ],
"sourceType": "module" "sourceType": "module"

@ -1,9 +0,0 @@
<script>
import App from './src/App.svelte';
</script>
<svelte:boundary>
<App />
{#snippet pending()}{/snippet}
</svelte:boundary>

@ -12,7 +12,7 @@
<script type="module"> <script type="module">
import { mount, hydrate, unmount } from 'svelte'; import { mount, hydrate, unmount } from 'svelte';
import App from '/Wrapper.svelte'; import App from '/src/App.svelte';
globalThis.delayed = (v, ms = 1000) => { globalThis.delayed = (v, ms = 1000) => {
return new Promise((f) => { return new Promise((f) => {

@ -16,11 +16,13 @@
"start": "node run.js" "start": "node run.js"
}, },
"devDependencies": { "devDependencies": {
"@sveltejs/vite-plugin-svelte": "^4.0.0-next.6", "@sveltejs/vite-plugin-svelte": "^6.2.0",
"@types/node": "^24.5.2",
"polka": "^1.0.0-next.25", "polka": "^1.0.0-next.25",
"svelte": "workspace:*", "svelte": "workspace:*",
"tinyglobby": "^0.2.12", "tinyglobby": "^0.2.12",
"vite": "^5.4.20", "vite": "^7.1.5",
"vite-plugin-inspect": "^0.8.4" "vite-plugin-devtools-json": "^1.0.0",
"vite-plugin-inspect": "^11.3.3"
} }
} }

@ -4,7 +4,6 @@ import path from 'node:path';
import { fileURLToPath } from 'node:url'; import { fileURLToPath } from 'node:url';
import polka from 'polka'; import polka from 'polka';
import { createServer as createViteServer } from 'vite'; import { createServer as createViteServer } from 'vite';
import { render } from 'svelte/server';
import './ssr-common.js'; import './ssr-common.js';
const PORT = process.env.PORT || '5173'; const PORT = process.env.PORT || '5173';
@ -23,8 +22,11 @@ polka()
.use(async (req, res) => { .use(async (req, res) => {
const template = fs.readFileSync(path.resolve(__dirname, 'index.html'), 'utf-8'); const template = fs.readFileSync(path.resolve(__dirname, 'index.html'), 'utf-8');
const transformed_template = await vite.transformIndexHtml(req.url, template); const transformed_template = await vite.transformIndexHtml(req.url, template);
const { render } = await vite.ssrLoadModule('svelte/server');
const { default: App } = await vite.ssrLoadModule('/src/App.svelte'); const { default: App } = await vite.ssrLoadModule('/src/App.svelte');
const { head, body } = render(App);
const { head, body } = await render(App);
const html = transformed_template const html = transformed_template
.replace(`<!--ssr-head-->`, head) .replace(`<!--ssr-head-->`, head)

@ -5,7 +5,7 @@ import { render } from 'svelte/server';
import App from './src/App.svelte'; import App from './src/App.svelte';
import './ssr-common.js'; import './ssr-common.js';
const { head, body } = render(App); const { head, body } = await render(App);
const rendered = fs const rendered = fs
.readFileSync(path.resolve('./dist/client/index.html'), 'utf-8') .readFileSync(path.resolve('./dist/client/index.html'), 'utf-8')

@ -1,13 +1,14 @@
import { defineConfig } from 'vite'; import { defineConfig } from 'vite';
import inspect from 'vite-plugin-inspect'; import inspect from 'vite-plugin-inspect';
import { svelte } from '@sveltejs/vite-plugin-svelte'; import { svelte } from '@sveltejs/vite-plugin-svelte';
import devtools from 'vite-plugin-devtools-json';
export default defineConfig({ export default defineConfig({
build: { build: {
minify: false minify: false
}, },
plugins: [inspect(), svelte()], plugins: [devtools(), inspect(), svelte()],
optimizeDeps: { optimizeDeps: {
// svelte is a local workspace package, optimizing it would require dev server restarts with --force for every change // svelte is a local workspace package, optimizing it would require dev server restarts with --force for every change

File diff suppressed because it is too large Load Diff
Loading…
Cancel
Save