@foldkit/vite-plugin 0.20.2-canary.af3250ec30c5 → 0.20.2-canary.b950c054bbe3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/dist/index.js +15 -15
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @foldkit/vite-plugin
|
|
2
2
|
|
|
3
|
-
Vite plugin for Foldkit: view identity branding for the differ, plus
|
|
3
|
+
Vite plugin for Foldkit: view identity branding for the differ, plus state-preserving live reload.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -34,7 +34,7 @@ This plugin supplies that identity. At build time, in dev and production alike,
|
|
|
34
34
|
|
|
35
35
|
Foldkit core modules are never instrumented, and functions that never return vnodes are wrapped inertly. Builds without this plugin fall back to positional matching plus keys, where branch points need hand-written keys.
|
|
36
36
|
|
|
37
|
-
##
|
|
37
|
+
## State-preserving live reload
|
|
38
38
|
|
|
39
39
|
When you save a file during development, the plugin:
|
|
40
40
|
|
|
@@ -51,7 +51,7 @@ The plugin uses Vite's WebSocket connection to communicate between the dev serve
|
|
|
51
51
|
- **On file change**: The browser sends the current Model to the Vite server for preservation.
|
|
52
52
|
- **On reload**: The browser requests the preserved Model from the server and initializes the Foldkit Runtime with it.
|
|
53
53
|
|
|
54
|
-
The Model survives
|
|
54
|
+
The Model survives development reloads but clears on a manual browser refresh, so a refresh still resets the application.
|
|
55
55
|
|
|
56
56
|
## Server rendering dev host
|
|
57
57
|
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Array, Console, Data, Duration, Effect, Exit, Fiber, HashMap, HashSet, Match, Option, Predicate, Queue, Ref, Schedule, Schema, Stream, pipe, } from 'effect';
|
|
2
2
|
import { Event as DevToolsEvent, EventFrame, RequestFrame, Response, ResponseFrame, } from 'foldkit/devtools-protocol';
|
|
3
|
-
import { PreserveModelMessage, RequestModelMessage, RestoreModelMessage, } from 'foldkit/
|
|
3
|
+
import { PreserveModelMessage, RequestModelMessage, RestoreModelMessage, } from 'foldkit/model-preservation';
|
|
4
4
|
import { createRequire } from 'node:module';
|
|
5
5
|
import { resolve } from 'node:path';
|
|
6
6
|
import { WebSocketServer } from 'ws';
|
|
@@ -115,26 +115,26 @@ const makeState = Effect.gen(function* () {
|
|
|
115
115
|
const encodeResponseFrameJson = Schema.encodeUnknownSync(Schema.fromJsonString(ResponseFrame));
|
|
116
116
|
// HANDLERS
|
|
117
117
|
const handlePreserveModelReceived = (state, payload) => Exit.match(Schema.decodeUnknownExit(PreserveModelMessage)(payload), {
|
|
118
|
-
onFailure: error => Console.warn('[foldkit:
|
|
119
|
-
onSuccess: ({ id, model,
|
|
120
|
-
const existingFlag = Option.exists(HashMap.get(current, id), ({
|
|
118
|
+
onFailure: error => Console.warn('[foldkit:preserve] failed to decode preserve-model payload', error),
|
|
119
|
+
onSuccess: ({ id, model, isReloadFlush }) => Ref.update(state.preservedModels, current => {
|
|
120
|
+
const existingFlag = Option.exists(HashMap.get(current, id), ({ isReloadFlush }) => isReloadFlush);
|
|
121
121
|
const entry = {
|
|
122
122
|
model,
|
|
123
|
-
|
|
123
|
+
isReloadFlush: isReloadFlush === true || existingFlag,
|
|
124
124
|
};
|
|
125
125
|
return HashMap.set(current, id, entry);
|
|
126
126
|
}),
|
|
127
127
|
});
|
|
128
128
|
const handleRequestModelReceived = (server, state, payload) => Exit.match(Schema.decodeUnknownExit(RequestModelMessage)(payload), {
|
|
129
|
-
onFailure: error => Console.warn('[foldkit:
|
|
129
|
+
onFailure: error => Console.warn('[foldkit:preserve] failed to decode request-model payload', error),
|
|
130
130
|
onSuccess: ({ id }) => Effect.gen(function* () {
|
|
131
131
|
const current = yield* Ref.get(state.preservedModels);
|
|
132
132
|
const sendRestore = (model) => Effect.sync(() => server.ws.send('foldkit:restore-model', Schema.encodeUnknownSync(RestoreModelMessage)(RestoreModelMessage.make({ id, model }))));
|
|
133
133
|
yield* Option.match(HashMap.get(current, id), {
|
|
134
134
|
onNone: () => sendRestore(undefined),
|
|
135
135
|
onSome: entry => {
|
|
136
|
-
if (entry.
|
|
137
|
-
const served = { ...entry,
|
|
136
|
+
if (entry.isReloadFlush) {
|
|
137
|
+
const served = { ...entry, isReloadFlush: false };
|
|
138
138
|
return Ref.update(state.preservedModels, HashMap.set(id, served)).pipe(Effect.flatMap(() => sendRestore(entry.model)));
|
|
139
139
|
}
|
|
140
140
|
return Ref.update(state.preservedModels, HashMap.remove(id)).pipe(Effect.flatMap(() => sendRestore(undefined)));
|
|
@@ -142,7 +142,7 @@ const handleRequestModelReceived = (server, state, payload) => Exit.match(Schema
|
|
|
142
142
|
});
|
|
143
143
|
}),
|
|
144
144
|
});
|
|
145
|
-
const handleHotUpdateFired = (state) => Ref.update(state.preservedModels, current => HashMap.map(current, entry => ({ ...entry,
|
|
145
|
+
const handleHotUpdateFired = (state) => Ref.update(state.preservedModels, current => HashMap.map(current, entry => ({ ...entry, isReloadFlush: true })));
|
|
146
146
|
const handleBrowserEventFrameReceived = (state, data, client) => Exit.match(Schema.decodeUnknownExit(EventFrame)(data), {
|
|
147
147
|
onFailure: error => Console.warn('[foldkit:devTools] failed to decode browser event frame', error),
|
|
148
148
|
onSuccess: frame => DevToolsEvent.match(frame.event, {
|
|
@@ -316,7 +316,7 @@ const main = (server, events, options) => Effect.gen(function* () {
|
|
|
316
316
|
};
|
|
317
317
|
yield* registerViteWsHandlers(server, state, enqueue);
|
|
318
318
|
// NOTE: Forked rather than awaited because binding the relay can retry for
|
|
319
|
-
// seconds.
|
|
319
|
+
// seconds. Model preservation is independent of the relay, and the runtime
|
|
320
320
|
// gives up on its boot-time model request in well under a second, so
|
|
321
321
|
// sequencing the dispatch loop behind the bind would cost model
|
|
322
322
|
// preservation whenever the port is contended.
|
|
@@ -328,8 +328,8 @@ const main = (server, events, options) => Effect.gen(function* () {
|
|
|
328
328
|
// PLUGIN ENTRY
|
|
329
329
|
/**
|
|
330
330
|
* Foldkit's Vite plugin set: the view-identity branding transform and
|
|
331
|
-
* DevTools overlay injection (dev and build), plus
|
|
332
|
-
*
|
|
331
|
+
* DevTools overlay injection (dev and build), plus Model preservation across
|
|
332
|
+
* reloads and the optional DevTools MCP relay (dev only). Returned as
|
|
333
333
|
* an array; Vite flattens nested plugin arrays, so `plugins: [foldkit()]`
|
|
334
334
|
* keeps working.
|
|
335
335
|
*/
|
|
@@ -371,8 +371,8 @@ export const foldkit = (options = {}) => {
|
|
|
371
371
|
return Fiber.interrupt(fiber);
|
|
372
372
|
}
|
|
373
373
|
});
|
|
374
|
-
const
|
|
375
|
-
name: 'foldkit
|
|
374
|
+
const reloadPlugin = {
|
|
375
|
+
name: 'foldkit',
|
|
376
376
|
apply: 'serve',
|
|
377
377
|
config: userConfig => ({
|
|
378
378
|
optimizeDeps: {
|
|
@@ -406,7 +406,7 @@ export const foldkit = (options = {}) => {
|
|
|
406
406
|
foldkitBuildToken(options.buildId),
|
|
407
407
|
foldkitViewIdentity(),
|
|
408
408
|
devToolsOverlayPlugin(),
|
|
409
|
-
|
|
409
|
+
reloadPlugin,
|
|
410
410
|
];
|
|
411
411
|
if (options.ssr === undefined) {
|
|
412
412
|
return shared;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@foldkit/vite-plugin",
|
|
3
|
-
"version": "0.20.2-canary.
|
|
4
|
-
"description": "Vite plugin for Foldkit
|
|
3
|
+
"version": "0.20.2-canary.b950c054bbe3",
|
|
4
|
+
"description": "Vite plugin for Foldkit with state-preserving live reload",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
],
|
|
18
18
|
"peerDependencies": {
|
|
19
19
|
"effect": "4.0.0-rc.112",
|
|
20
|
-
"foldkit": "0.158.2-canary.
|
|
20
|
+
"foldkit": "0.158.2-canary.b950c054bbe3",
|
|
21
21
|
"vite": "^7.0.0 || ^8.0.0"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
@@ -34,14 +34,14 @@
|
|
|
34
34
|
"vite": "^8.2.2",
|
|
35
35
|
"vite7": "npm:vite@^7.3.6",
|
|
36
36
|
"vitest": "^4.1.11",
|
|
37
|
-
"foldkit": "0.158.2-canary.
|
|
37
|
+
"foldkit": "0.158.2-canary.b950c054bbe3"
|
|
38
38
|
},
|
|
39
39
|
"keywords": [
|
|
40
40
|
"vite",
|
|
41
41
|
"vite-plugin",
|
|
42
42
|
"foldkit",
|
|
43
|
-
"
|
|
44
|
-
"
|
|
43
|
+
"live-reload",
|
|
44
|
+
"state-preservation"
|
|
45
45
|
],
|
|
46
46
|
"author": "Devin Jameson",
|
|
47
47
|
"license": "MIT",
|