mirror of https://github.com/sveltejs/svelte
commit
68a10b73b9
@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'svelte': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
fix: ensure tracking returns true, even if in unowned
|
||||||
@ -0,0 +1,16 @@
|
|||||||
|
import { flushSync } from 'svelte';
|
||||||
|
import { test } from '../../test';
|
||||||
|
|
||||||
|
export default test({
|
||||||
|
async test({ assert, target, logs }) {
|
||||||
|
const b1 = target.querySelector('button');
|
||||||
|
|
||||||
|
b1?.click();
|
||||||
|
flushSync();
|
||||||
|
|
||||||
|
assert.htmlEqual(
|
||||||
|
target.innerHTML,
|
||||||
|
`<o>Store: new</o><p>Text: new message</p><button>Change Store</button>`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
});
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
<script>
|
||||||
|
import { writable, fromStore, toStore } from "svelte/store";
|
||||||
|
|
||||||
|
const store = writable("previous");
|
||||||
|
let text = $derived(fromStore(store).current + " message");
|
||||||
|
|
||||||
|
text; // read derived in a non-tracking context
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<o>Store: {$store}</o>
|
||||||
|
<p>Text: {text}</p>
|
||||||
|
<button onclick={() => { store.set("new"); }}>Change Store</button>
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
import fs from 'node:fs';
|
||||||
|
|
||||||
|
const arg = process.argv[2];
|
||||||
|
|
||||||
|
/** @type {URL} */
|
||||||
|
let url;
|
||||||
|
|
||||||
|
try {
|
||||||
|
url = new URL(arg);
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`${arg} is not a URL`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (url.origin !== 'https://svelte.dev' || !url.pathname.startsWith('/playground/')) {
|
||||||
|
console.error(`${arg} is not a Svelte playground URL`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
let files;
|
||||||
|
|
||||||
|
if (url.hash.length > 1) {
|
||||||
|
const decoded = atob(url.hash.slice(1).replaceAll('-', '+').replaceAll('_', '/'));
|
||||||
|
// putting it directly into the blob gives a corrupted file
|
||||||
|
const u8 = new Uint8Array(decoded.length);
|
||||||
|
for (let i = 0; i < decoded.length; i++) {
|
||||||
|
u8[i] = decoded.charCodeAt(i);
|
||||||
|
}
|
||||||
|
const stream = new Blob([u8]).stream().pipeThrough(new DecompressionStream('gzip'));
|
||||||
|
const json = await new Response(stream).text();
|
||||||
|
|
||||||
|
files = JSON.parse(json).files;
|
||||||
|
} else {
|
||||||
|
const id = url.pathname.split('/')[2];
|
||||||
|
const response = await fetch(`https://svelte.dev/playground/api/${id}.json`);
|
||||||
|
|
||||||
|
files = (await response.json()).components.map((data) => {
|
||||||
|
const basename = `${data.name}.${data.type}`;
|
||||||
|
|
||||||
|
return {
|
||||||
|
type: 'file',
|
||||||
|
name: basename,
|
||||||
|
basename,
|
||||||
|
contents: data.source,
|
||||||
|
text: true
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const file of files) {
|
||||||
|
fs.writeFileSync(`src/${file.name}`, file.contents);
|
||||||
|
}
|
||||||
@ -0,0 +1,45 @@
|
|||||||
|
import fs from 'node:fs';
|
||||||
|
|
||||||
|
const files = [];
|
||||||
|
|
||||||
|
for (const basename of fs.readdirSync('src')) {
|
||||||
|
if (fs.statSync(`src/${basename}`).isDirectory()) continue;
|
||||||
|
|
||||||
|
files.push({
|
||||||
|
type: 'file',
|
||||||
|
name: basename,
|
||||||
|
basename,
|
||||||
|
contents: fs.readFileSync(`src/${basename}`, 'utf-8'),
|
||||||
|
text: true // TODO might not be
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
const payload = JSON.stringify({
|
||||||
|
name: 'sandbox',
|
||||||
|
files
|
||||||
|
});
|
||||||
|
|
||||||
|
async function compress(payload) {
|
||||||
|
const reader = new Blob([payload])
|
||||||
|
.stream()
|
||||||
|
.pipeThrough(new CompressionStream('gzip'))
|
||||||
|
.getReader();
|
||||||
|
|
||||||
|
let buffer = '';
|
||||||
|
for (;;) {
|
||||||
|
const { done, value } = await reader.read();
|
||||||
|
|
||||||
|
if (done) {
|
||||||
|
reader.releaseLock();
|
||||||
|
return btoa(buffer).replaceAll('+', '-').replaceAll('/', '_');
|
||||||
|
} else {
|
||||||
|
for (let i = 0; i < value.length; i++) {
|
||||||
|
// decoding as utf-8 will make btoa reject the string
|
||||||
|
buffer += String.fromCharCode(value[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const hash = await compress(payload);
|
||||||
|
console.log(`https://svelte.dev/playground/untitled#${hash}`);
|
||||||
Loading…
Reference in new issue