diff --git a/CHANGELOG.md b/CHANGELOG.md index e4b64a8b..806ef72f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,10 @@ - `props` in a component declared without props (`component C()`) is `UNBOUND` (RG-4b); it read `undefined`. - `guide/async.md`: "One store over the server"; the `GUESS_WHILE_LOADING` advice says what holds when a selection changes while a guess is out (05 DV-22). +- Under `vite dev`, an edit inside a dependency's components re-renders them in place instead of reloading the page: + the module's top-level sources and every other component's state are kept. An edit to the module's top level or to + an entry still reloads. The runtime's new `@reactivescript/runtime/hot` entry does the swap; it needs a + `@solidjs/vite-plugin` with the front end's `hotUpdate` hook. ## 0.3.1 diff --git a/compiler/README.md b/compiler/README.md index 17769fb8..94a2bdd8 100644 --- a/compiler/README.md +++ b/compiler/README.md @@ -88,8 +88,14 @@ What happens to a `.rx` module in Vite: The app mounts a program with `createApp` from `@reactivescript/runtime` (`../runtime`, CP-4a), as the examples do. -Not yet: hot updates of `.rx` modules are untested; server rendering in Vite -needs a request-scoped app for server functions to run in. +Hot updates: with a Solid plugin that has the front end's `hotUpdate` hook, +an edit inside a dependency's components (markup, logic, `\n \n
{said}
\n}\n`; + writeFileSync(panel, source()); + const server = await vite.createServer(config(dir, "hot/main.rx")); await server.listen(0); + await drive("hot (dev)", server.resolvedUrls.local[0], async page => { + const seen = async () => ({ + panel: (await page.textContent(".panel").catch(() => "")).trim(), other: (await page.textContent(".other").catch(() => "")).trim(), + color: await page.$eval(".panel", e => getComputedStyle(e).color).catch(() => ""), kept: await page.evaluate(() => window.__kept === 1).catch(() => false), + said: (await page.textContent(".said").catch(() => "")).trim(), + }); + const until = async (what, want) => { + let got; + for (let i = 0; i < 50; i++) { got = await seen(); if (Object.entries(want).every(([k, v]) => got[k] === v)) return; await page.waitForTimeout(100); } + throw new Error(`${what}: ${JSON.stringify(got)}, not ${JSON.stringify(want)}`); + }; + for (let i = 0; i < 3; i++) await page.click(".panel"); + for (let i = 0; i < 2; i++) await page.click(".other"); + await page.evaluate(() => { window.__kept = 1; }); + await until("before the edits", { panel: "total 3", other: "other 2" }); + // the module-level source and the other module's component state survive; the page is not reloaded + writeFileSync(panel, source({ label: "sum" })); + await until("after a markup edit", { panel: "sum 3", other: "other 2", kept: true }); + writeFileSync(panel, source({ label: "sum", color: "rgb(255, 0, 0)" })); + await until("after a