Skip to content

Commit 94f9fb2

Browse files
authored
Merge pull request #40 from tomoam/update-up-to-20230505
2 parents 7bdba72 + 723ce08 commit 94f9fb2

File tree

12 files changed

+69
-25
lines changed

12 files changed

+69
-25
lines changed

content/tutorial/01-svelte/02-reactivity/02-reactive-declarations/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ let count = 0;
2323
+++<p>{count} doubled is {doubled}</p>+++
2424
```
2525

26-
もちろん、代わりに `{count * 2}` とマークアップに書くだけでもよいでしょう。リアクティブな値を使用する必要はありません。リアクティブな値は、複数回参照する必要がある場合や、*他の* リアクティブな値に依存する値がある場合に特に価値があります。
26+
もちろん、代わりに `{count * 2}` とマークアップに書くだけでもよいでしょう。リアクティブな値を使用する必要はありません。リアクティブな値は、複数回参照する必要がある場合や、*他の* リアクティブな値に依存する値がある場合に使用する価値があります。
27+
28+
> リアクティブ宣言(reactive declarations)とリアクティブステートメント(reactive statements)は、他のスクリプトコードの後、かつコンポーネントのマークアップがレンダリングされる前に実行されることにご注意ください。

content/tutorial/03-sveltekit/06-forms/05-customizing-use-enhance/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const actions = {
6767
データを保存している間は、メッセージを表示することができます:
6868

6969
```svelte
70-
/// file: App.svelte
70+
/// file: src/routes/+page.svelte
7171
<ul class="todos">
7272
<!-- ... -->
7373
</ul>

content/tutorial/03-sveltekit/09-errors-and-redirects/02-error-pages/README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ title: Error pages
1919
</span>
2020
```
2121

22-
> `page` store を使用していますが、これは後の章で詳細に学習します。
23-
2422
`+error.svelte` コンポーネントは最上位(root)の `+layout.svelte` の内側でレンダリングされます。よりきめ細やかな `+error.svelte` 境界を作ることもできます。
2523

2624
```svelte

content/tutorial/04-advanced-sveltekit/01-hooks/04-handleerror/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,4 @@ export function handleError({ event, error }) {
4949
<h1>{$page.status}</h1>
5050
<p>{$page.error.message}</p>
5151
<p>error code: {$page.error.code}</p>
52-
```
52+
```

content/tutorial/common/src/__client.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,4 @@ if (import.meta.hot) {
9797
import.meta.hot.on('vite:beforeUpdate', (event) => {
9898
post({ type: 'hmr', data: event.updates });
9999
});
100-
101-
import.meta.hot.on('svelte:warnings', (data) => {
102-
post({ type: 'warnings', data });
103-
});
104100
}

content/tutorial/common/svelte.config.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ const config = {
88
},
99

1010
vitePlugin: {
11-
experimental: {
12-
// This feature enables compile-time warnings to be
13-
// visible in the learn.svelte.dev editor
14-
sendWarningsToBrowser: true
11+
// This enables compile-time warnings to be
12+
// visible in the learn.svelte.dev editor
13+
onwarn: (warning, defaultHandler) => {
14+
console.log('svelte:warnings:%s', JSON.stringify(warning));
15+
defaultHandler(warning);
1516
}
1617
}
1718
};

src/lib/client/adapters/webcontainer/index.js

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ import * as yootils from 'yootils';
55
import { escape_html, get_depth } from '../../../utils.js';
66
import { ready } from '../common/index.js';
77

8+
/**
9+
* @typedef {import("../../../../routes/tutorial/[slug]/state.js").CompilerWarning} CompilerWarning
10+
*/
11+
812
const converter = new AnsiToHtml({
913
fg: 'var(--sk-text-3)'
1014
});
@@ -17,9 +21,10 @@ let vm;
1721
* @param {import('svelte/store').Writable<Error | null>} error
1822
* @param {import('svelte/store').Writable<{ value: number, text: string }>} progress
1923
* @param {import('svelte/store').Writable<string[]>} logs
24+
* @param {import('svelte/store').Writable<Record<string, CompilerWarning[]>>} warnings
2025
* @returns {Promise<import('$lib/types').Adapter>}
2126
*/
22-
export async function create(base, error, progress, logs) {
27+
export async function create(base, error, progress, logs, warnings) {
2328
if (/safari/i.test(navigator.userAgent) && !/chrome/i.test(navigator.userAgent)) {
2429
throw new Error('WebContainers are not supported by Safari');
2530
}
@@ -45,12 +50,40 @@ export async function create(base, error, progress, logs) {
4550
}
4651
});
4752

53+
/** @type {Record<string, CompilerWarning[]>} */
54+
let $warnings;
55+
warnings.subscribe((value) => $warnings = value);
56+
57+
/** @type {any} */
58+
let timeout;
59+
60+
/** @param {number} msec */
61+
function schedule_to_update_warning(msec) {
62+
clearTimeout(timeout);
63+
timeout = setTimeout(() => warnings.set($warnings), msec);
64+
}
65+
4866
const log_stream = () =>
4967
new WritableStream({
5068
write(chunk) {
5169
if (chunk === '\x1B[1;1H') {
5270
// clear screen
5371
logs.set([]);
72+
73+
} else if (chunk?.startsWith('svelte:warnings:')) {
74+
/** @type {CompilerWarning} */
75+
const warn = JSON.parse(chunk.slice(16));
76+
const current = $warnings[warn.filename];
77+
78+
if (!current) {
79+
$warnings[warn.filename] = [warn];
80+
// the exact same warning may be given multiple times in a row
81+
} else if (!current.some((s) => (s.code === warn.code && s.pos === warn.pos))) {
82+
current.push(warn);
83+
}
84+
85+
schedule_to_update_warning(100);
86+
5487
} else {
5588
const log = converter.toHtml(escape_html(chunk)).replace(/\n/g, '<br>');
5689
logs.update(($logs) => [...$logs, log]);
@@ -154,6 +187,17 @@ export async function create(base, error, progress, logs) {
154187
...force_delete
155188
];
156189

190+
// initialize warnings of written files
191+
to_write
192+
.filter((stub) => stub.type === 'file' && $warnings[stub.name])
193+
.forEach((stub) => $warnings[stub.name] = []);
194+
// remove warnings of deleted files
195+
to_delete
196+
.filter((stubname) => $warnings[stubname])
197+
.forEach((stubname) => delete $warnings[stubname]);
198+
199+
warnings.set($warnings);
200+
157201
current_stubs = stubs_to_map(stubs);
158202

159203
// For some reason, server-ready is fired again when the vite dev server is restarted.
@@ -221,6 +265,10 @@ export async function create(base, error, progress, logs) {
221265

222266
tree[basename] = to_file(file);
223267

268+
// initialize warnings of this file
269+
$warnings[file.name] = [];
270+
schedule_to_update_warning(100);
271+
224272
await vm.mount(root);
225273

226274
current_stubs.set(file.name, file);

src/routes/tutorial/[slug]/Editor.svelte

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
import { HighlightStyle } from '@codemirror/language';
1616
import { syntaxHighlighting } from '@codemirror/language';
1717
import { afterNavigate, beforeNavigate } from '$app/navigation';
18-
import { files, selected_file, selected_name, update_file, warnings } from './state.js';
18+
import { files, selected_file, selected_name, update_file } from './state.js';
19+
import { warnings } from './adapter.js';
1920
import './codemirror.css';
2021
2122
/** @type {HTMLDivElement} */

src/routes/tutorial/[slug]/Output.svelte

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import Chrome from './Chrome.svelte';
66
import Loading from './Loading.svelte';
77
import { base, error, logs, progress, subscribe } from './adapter';
8-
import { warnings } from './state';
98
109
/** @type {import('$lib/types').Exercise} */
1110
export let exercise;
@@ -63,11 +62,6 @@
6362
}, 1000);
6463
} else if (e.data.type === 'ping-pause') {
6564
clearTimeout(timeout);
66-
} else if (e.data.type === 'warnings') {
67-
warnings.update(($warnings) => ({
68-
...$warnings,
69-
[e.data.data.normalizedFilename]: e.data.data.allWarnings
70-
}));
7165
}
7266
}
7367

src/routes/tutorial/[slug]/Sidebar.svelte

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@
142142
--color: rgba(255, 0, 0, 0.1);
143143
}
144144
145+
:global(body.dark) .text :global(pre) :global(.highlight.remove) {
146+
--color: rgba(255, 0, 0, 0.27);
147+
}
148+
145149
/** this probably belongs in site-kit */
146150
.text :global(p) :global(a) :global(code) {
147151
color: var(--sk-theme-1);

0 commit comments

Comments
 (0)