Skip to content

feat: add svelte version selector to REPL #1319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 31, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
add svelte version selector to REPL
  • Loading branch information
7nik committed Apr 22, 2025
commit 6fe6f2bf1c9ea1a4585e6771c2822ca928ca4c50
23 changes: 22 additions & 1 deletion packages/repl/src/lib/Input/ComponentSelector.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,15 @@

<button disabled={!can_migrate} onclick={migrate}>Migrate to Svelte 5, if possible</button>

<label class="option">
<span>Svelte version</span>
<input
value={workspace.svelte_version}
placeholder="latest"
onchange={(ev) => (workspace.svelte_version = ev.currentTarget.value)}
/>
</label>

{#if download}
<button onclick={download}>Download app</button>
{/if}
Expand Down Expand Up @@ -278,7 +287,7 @@
}
}

input {
.file-tabs input {
position: absolute;
width: calc(100% - var(--padding-left) - var(--padding-right));
border: none;
Expand Down Expand Up @@ -318,6 +327,18 @@
justify-content: flex-end;
}

.option input {
background: transparent;
border: 1px solid var(--sk-border);
border-radius: var(--sk-border-radius);
color: currentColor;
width: 0;
flex: 1;
padding: 0.2rem 0.6rem;
height: 3.2rem;
font: var(--sk-font-ui-medium);
}

svg {
position: relative;
overflow: hidden;
Expand Down
1 change: 1 addition & 0 deletions packages/repl/src/lib/Output/PaneWithPanel.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@
}

section {
position: relative;
overflow: hidden;
}
</style>
20 changes: 9 additions & 11 deletions packages/repl/src/lib/Output/Viewer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -313,9 +313,15 @@
srcdoc={BROWSER ? srcdoc : ''}
></iframe>

{#if bundle?.error}
<ErrorOverlay error={bundle.error} />
{/if}
<div class="overlay">
{#if bundle?.error}
<ErrorOverlay error={bundle.error} />
{:else if error}
<Message kind="error" details={error} />
{:else if status || !bundle}
<Message kind="info" truncate>{status || 'loading Svelte compiler...'}</Message>
{/if}
</div>
{/snippet}

<div class="iframe-container">
Expand Down Expand Up @@ -344,14 +350,6 @@
{:else}
{@render main()}
{/if}

<div class="overlay">
{#if error}
<Message kind="error" details={error} />
{:else if status || !bundle}
<Message kind="info" truncate>{status || 'loading Svelte compiler...'}</Message>
{/if}
</div>
</div>

<style>
Expand Down
28 changes: 16 additions & 12 deletions packages/repl/src/lib/Repl.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@

async function rebundle() {
bundler!.bundle(workspace.files as File[], {
svelte_version: workspace.svelte_version,
tailwind: workspace.tailwind
});
}
Expand All @@ -112,7 +113,10 @@
const bundler = BROWSER
? new Bundler({
svelte_version: svelteVersion,
onversion,
onversion: (version) => {
workspace.svelte_version = version;
onversion?.(version);
},
onstatus: (message) => {
if (message) {
// show bundler status, but only after time has elapsed, to
Expand Down Expand Up @@ -204,7 +208,7 @@
{injectedCSS}
{previewTheme}
{workspace}
runtimeError={status_visible ? runtime_error : null}
runtimeError={runtime_error}
/>
</section>
{/snippet}
Expand All @@ -229,13 +233,13 @@
height: 100%;
}

:global {
section {
position: relative;
padding: var(--sk-pane-controls-height) 0 0 0;
height: 100%;
box-sizing: border-box;
section {
position: relative;
padding: var(--sk-pane-controls-height) 0 0 0;
height: 100%;
box-sizing: border-box;

:global {
& > :first-child {
position: absolute;
top: 0;
Expand All @@ -250,11 +254,11 @@
height: 100%;
}
}
}

[data-pane='main'] > svelte-split-pane-divider::after {
height: calc(100% - var(--sk-pane-controls-height));
top: var(--sk-pane-controls-height);
}
:global [data-pane='main'] > svelte-split-pane-divider::after {
height: calc(100% - var(--sk-pane-controls-height));
top: var(--sk-pane-controls-height);
}
}

Expand Down
12 changes: 11 additions & 1 deletion packages/repl/src/lib/Workspace.svelte.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class Workspace {
});
compiled = $state<Record<string, Compiled>>({});

#svelte_version: string;
#svelte_version = $state('');
#readonly = false; // TODO do we need workspaces for readonly stuff?
#files = $state.raw<Item[]>([]);
#current = $state.raw() as File;
Expand Down Expand Up @@ -479,6 +479,16 @@ export class Workspace {
this.#onupdate(this.#current);
}

get svelte_version() {
return this.#svelte_version;
}

set svelte_version(value) {
this.#svelte_version = value;
this.#update_file(this.#current);
this.#reset_diagnostics();
}

get vim() {
return this.#vim;
}
Expand Down
35 changes: 25 additions & 10 deletions packages/repl/src/lib/workers/bundler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,25 +42,21 @@ const ESM_ENV = '__esm-env.js';

let current_id: number;

let ready: ReturnType<typeof load_svelte>;

self.addEventListener('message', async (event: MessageEvent<BundleMessageData>) => {
switch (event.data.type) {
case 'init': {
ready = load_svelte(event.data.svelte_version, (version) => {
self.postMessage({
type: 'version',
message: version
});
});

get_svelte(event.data.svelte_version);
break;
}

case 'bundle': {
try {
const { svelte, version: svelte_version, can_use_experimental_async } = await ready;
const { uid, files, options } = event.data;
const {
svelte,
version: svelte_version,
can_use_experimental_async
} = await get_svelte(options.svelte_version);

current_id = uid;

Expand Down Expand Up @@ -92,6 +88,25 @@ self.addEventListener('message', async (event: MessageEvent<BundleMessageData>)
}
});

let ready: ReturnType<typeof load_svelte>;
let ready_version: string;

function get_svelte(svelte_version: string) {
if (ready_version === svelte_version) return ready;

self.postMessage({ type: 'status', message: `fetching svelte@${svelte_version}` });
ready_version = svelte_version;
ready = load_svelte(svelte_version || 'latest');
ready.then(({ version }) => {
ready_version = version;
self.postMessage({
type: 'version',
message: version
});
});
return ready;
}

const ABORT = { aborted: true };

let previous: {
Expand Down
10 changes: 7 additions & 3 deletions packages/repl/src/lib/workers/npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ const packages = new Map<string, Promise<Package>>();

const pkg_pr_new_regex = /^(pr|commit|branch)-(.+)/;

export async function load_svelte(version: string, onresolve?: (resolved: string) => void) {
export async function load_svelte(version: string) {
if (version === 'local') {
await import(/* @vite-ignore */ `${location.origin}/svelte/compiler/index.js`);
} else {
if (!pkg_pr_new_regex.test(version)) {
version = await resolve_version('svelte', version);
onresolve?.(version);
const resolved_version = await resolve_version('svelte', version);
if (resolved_version) {
version = resolved_version;
} else {
throw new Error(`Failed to resolve svelte@${version}`);
}
}

const pkg = await fetch_package('svelte', version);
Expand Down
1 change: 1 addition & 0 deletions packages/repl/src/lib/workers/workers.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface MigrateOutput {
}

export interface BundleOptions {
svelte_version: string;
tailwind?: boolean;
runes?: boolean;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/site-kit/src/lib/styles/base.css
Original file line number Diff line number Diff line change
Expand Up @@ -157,10 +157,12 @@ button {
background-color: transparent;
border: none;
color: currentColor;
cursor: pointer;
}

button[disabled] {
color: var(--sk-fg-4);
cursor: not-allowed;
}

/* links ------------------------------------- */
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy