Skip to content

Commit 0ec3f3c

Browse files
authored
Merge branch 'main' into main
2 parents 838852d + 73922ea commit 0ec3f3c

File tree

11 files changed

+225
-72
lines changed

11 files changed

+225
-72
lines changed
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
NOTE: do not edit this file, it is generated in apps/svelte.dev/scripts/sync-docs/index.ts
3+
title: devtools-json
4+
---
5+
6+
The `devtools-json` add-on installs [`vite-plugin-devtools-json`](https://github.com/ChromeDevTools/vite-plugin-devtools-json/), which is a Vite plugin for generating a Chromium DevTools project settings file on-the-fly in the development server. This file is served from `/.well-known/appspecific/com.chrome.devtools.json` and tells Chromium browsers where your project's source code lives so that you can use [the workspaces feature](https://developer.chrome.com/docs/devtools/workspaces) to edit source files in the browser.
7+
8+
> [!NOTE]
9+
> Installing the plugin enables the feature for all users connecting to the dev server with a Chromium browser, and allows the browser to read and write all files within the directory. If using Chrome's AI Assistance feature, this may also result in data being sent to Google.
10+
11+
## Alternatives
12+
13+
If you'd prefer not to install the plugin, but still want to avoid seeing a message about the missing file, you have a couple of options.
14+
15+
Firstly, you can prevent the request from being issued on your machine by disabling the feature in your browser. You can do this in Chrome by visiting `chrome://flags` and disabling the "DevTools Project Settings". You may also be interested in disabling "DevTools Automatic Workspace Folders" since it’s closely related.
16+
17+
You can also prevent the web server from issuing a notice regarding the incoming request for all developers of your application by handling the request yourself. For example, you can create a file named `.well-known/appspecific/com.chrome.devtools.json` with the contents `"Go away, Chrome DevTools!"` or you can add logic to respond to the request in your [`handle`](https://svelte.dev/docs/kit/hooks#Server-hooks-handle) hook:
18+
19+
```js
20+
/// file: src/hooks.server.js
21+
import { dev } from '$app/environment';
22+
23+
export function handle({ event, resolve }) {
24+
if (dev && event.url.pathname === '/.well-known/appspecific/com.chrome.devtools.json') {
25+
return new Response(undefined, { status: 404 });
26+
}
27+
28+
return resolve(event);
29+
}
30+
```
31+
32+
## Usage
33+
34+
```bash
35+
npx sv add devtools-json
36+
```
37+
38+
## What you get
39+
40+
- `vite-plugin-devtools-json` added to your Vite plugin options

apps/svelte.dev/content/docs/cli/30-add-ons/60-devtools-json.md

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

apps/svelte.dev/content/docs/svelte/98-reference/.generated/client-errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ Cannot set prototype of `$state` object
125125
### state_unsafe_mutation
126126

127127
```
128-
Updating state inside a derived or a template expression is forbidden. If the value should not be reactive, declare it without `$state`
128+
Updating state inside `$derived(...)`, `$inspect(...)` or a template expression is forbidden. If the value should not be reactive, declare it without `$state`
129129
```
130130

131131
This error occurs when state is updated while evaluating a `$derived`. You might encounter it while trying to 'derive' two pieces of state in one go:

apps/svelte.dev/content/docs/svelte/98-reference/30-runtime-errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ Cannot set prototype of `$state` object
132132
### state_unsafe_mutation
133133

134134
```
135-
Updating state inside a derived or a template expression is forbidden. If the value should not be reactive, declare it without `$state`
135+
Updating state inside `$derived(...)`, `$inspect(...)` or a template expression is forbidden. If the value should not be reactive, declare it without `$state`
136136
```
137137

138138
This error occurs when state is updated while evaluating a `$derived`. You might encounter it while trying to 'derive' two pieces of state in one go:

apps/svelte.dev/src/routes/(authed)/playground/[id]/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
name = recovered.name;
7474
}
7575
76-
repl.set({ files, tailwind: recovered.tailwind ?? false });
76+
repl.set({ files, tailwind: recovered.tailwind ?? false, aliases: recovered.aliases });
7777
} catch {
7878
alert(`Couldn't load the code from the URL. Make sure you copied the link correctly.`);
7979
}

packages/repl/src/lib/Bundler.svelte.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,5 +56,22 @@ export default class Bundler {
5656
});
5757

5858
uid += 1;
59+
60+
return new Promise<void>((resolve) => {
61+
const destroy = $effect.root(() => {
62+
let first = true;
63+
$effect.pre(() => {
64+
this.result;
65+
if (first) {
66+
first = false;
67+
} else {
68+
destroy();
69+
// This isn't necessarily the result of this bundle call, as it could be
70+
// superseeded by another call to `bundle` before the result is set.
71+
resolve();
72+
}
73+
});
74+
});
75+
});
5976
}
6077
}

packages/repl/src/lib/Repl.svelte

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,16 @@
5252
text: true
5353
};
5454
55-
const workspace = new Workspace([dummy], {
55+
const workspace: Workspace = new Workspace([dummy], {
5656
initial: 'App.svelte',
5757
svelte_version: svelteVersion,
5858
onupdate() {
5959
rebundle();
6060
onchange?.();
6161
},
6262
onreset() {
63-
rebundle();
63+
// Return promise so we can await it in the workspace
64+
return rebundle();
6465
}
6566
});
6667
@@ -69,13 +70,33 @@
6970
return {
7071
imports: bundler!.result?.imports ?? [],
7172
files: workspace.files,
72-
tailwind: workspace.tailwind
73+
tailwind: workspace.tailwind,
74+
aliases: workspace.aliases
7375
};
7476
}
7577
76-
// TODO get rid
77-
export async function set(data: { files: File[]; tailwind?: boolean }) {
78-
workspace.reset(data.files, { tailwind: data.tailwind ?? false }, 'App.svelte');
78+
// Our own playground / v0 need this
79+
export async function set(data: {
80+
files: File[];
81+
tailwind?: boolean;
82+
aliases?: Record<string, string>;
83+
}) {
84+
// Await promise so that users (v0 in this case) can know when the bundling is done
85+
await workspace.reset(
86+
data.files,
87+
{ tailwind: data.tailwind ?? false, aliases: data.aliases },
88+
'App.svelte'
89+
);
90+
}
91+
92+
// v0 needs this
93+
export function get_asts() {
94+
return Object.fromEntries(
95+
Object.entries(workspace.compiled).map(([name, compiled]) => [
96+
name,
97+
compiled.result?.ast ?? null
98+
])
99+
);
79100
}
80101
81102
// TODO get rid
@@ -85,10 +106,11 @@
85106
86107
const toggleable: ReplContext['toggleable'] = writable(false);
87108
88-
async function rebundle() {
89-
bundler!.bundle(workspace.files as File[], {
109+
function rebundle() {
110+
return bundler!.bundle(workspace.files as File[], {
90111
tailwind: workspace.tailwind,
91-
fragments: workspace.compiler_options.fragments
112+
fragments: workspace.compiler_options.fragments,
113+
aliases: workspace.aliases
92114
});
93115
}
94116

packages/repl/src/lib/Workspace.svelte.ts

Lines changed: 33 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export class Workspace {
117117
#files = $state.raw<Item[]>([]);
118118
#current = $state.raw() as File;
119119
#vim = $state(false);
120+
#aliases = $state.raw(undefined) as undefined | Record<string, string>;
120121
#tailwind = $state(false);
121122

122123
#handlers = {
@@ -125,7 +126,7 @@ export class Workspace {
125126
};
126127

127128
#onupdate: (file: File) => void;
128-
#onreset: (items: Item[]) => void;
129+
#onreset: (items: Item[]) => void | Promise<void>;
129130

130131
// CodeMirror stuff
131132
states = new Map<string, EditorState>();
@@ -198,7 +199,7 @@ export class Workspace {
198199
initial?: string;
199200
readonly?: boolean;
200201
onupdate?: (file: File) => void;
201-
onreset?: (items: Item[]) => void;
202+
onreset?: (items: Item[]) => void | Promise<void>;
202203
} = {}
203204
) {
204205
this.#svelte_version = svelte_version;
@@ -400,16 +401,25 @@ export class Workspace {
400401
this.#onreset?.(this.#files);
401402
}
402403

403-
reset(new_files: Item[], options: { tailwind: boolean }, selected?: string) {
404+
reset(
405+
new_files: Item[],
406+
options: { tailwind: boolean; aliases?: Record<string, string> },
407+
selected?: string
408+
) {
404409
this.states.clear();
405410
this.set(new_files, selected);
406411

407412
this.mark_saved();
408413

409414
this.#tailwind = options.tailwind;
415+
this.#aliases = options.aliases;
410416

411-
this.#onreset(new_files);
412-
this.#reset_diagnostics();
417+
const bundle = this.#onreset(new_files);
418+
const diagnostics = this.#reset_diagnostics();
419+
420+
return Promise.all([bundle, diagnostics])
421+
.then(() => {})
422+
.catch(() => {});
413423
}
414424

415425
select(name: string) {
@@ -475,6 +485,15 @@ export class Workspace {
475485
}
476486
}
477487

488+
get aliases() {
489+
return this.#aliases;
490+
}
491+
492+
set aliases(value) {
493+
this.#aliases = value;
494+
this.#onupdate(this.#current);
495+
}
496+
478497
get tailwind() {
479498
return this.#tailwind;
480499
}
@@ -648,22 +667,26 @@ export class Workspace {
648667
files = [this.current, ...this.#files.slice(0, i), ...this.#files.slice(i + 1)];
649668
}
650669

651-
for (const file of files) {
652-
if (file.type !== 'file') continue;
653-
if (!is_svelte_file(file)) continue;
670+
const done = files.map((file) => {
671+
if (file.type !== 'file') return;
672+
if (!is_svelte_file(file)) return;
654673

655674
seen.push(file.name);
656675

657-
compile_file(file, this.#svelte_version, this.compiler_options).then((compiled) => {
676+
return compile_file(file, this.#svelte_version, this.compiler_options).then((compiled) => {
658677
this.compiled[file.name] = compiled;
659678
});
660-
}
679+
});
661680

662681
for (const key of keys) {
663682
if (!seen.includes(key)) {
664683
delete this.compiled[key];
665684
}
666685
}
686+
687+
return Promise.all(done)
688+
.then(() => {})
689+
.catch(() => {});
667690
}
668691

669692
#select(file: File) {

0 commit comments

Comments
 (0)