dinou 9.1.0 → 9.3.0
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/CHANGELOG.md +21 -0
- package/README.md +1 -1
- package/dinou/cli.js +1 -1
- package/dinou/core/cache-slot.js +117 -21
- package/dinou/core/client-webpack.jsx +6 -1
- package/dinou/core/client.jsx +6 -1
- package/dinou/core/get-jsx.js +75 -7
- package/dinou/core/handler.js +7 -3
- package/dinou/core/navigation.js +10 -5
- package/dinou/core/ppr-context.js +137 -10
- package/dinou/core/ppr-runtime.js +68 -11
- package/dinou/core/render-jsx-to-client-jsx.js +531 -55
- package/dinou/core/rsc-renderer.js +3 -0
- package/dinou/core/slot.js +8 -2
- package/dinou/esbuild/helpers-esbuild/swc-disk-cache.js +242 -242
- package/dinou/esbuild/plugins-esbuild/server-functions-plugin.js +253 -253
- package/dinou/esbuild/react-refresh/esm-hmr/client.js +209 -209
- package/dinou/index.d.ts +3 -2
- package/dinou/node/dev.js +2866 -2853
- package/dinou/package.json +1 -1
- package/dinou/rollup/react-refresh/esm-hmr/client.js +220 -220
- package/dinou/rollup/rollup-plugins/rollup-plugin-server-functions.js +182 -182
- package/dinou/server.d.ts +29 -29
- package/dinou/server.js +1 -1
- package/dinou/webpack/loaders/server-functions-loader.js +101 -101
- package/package.json +1 -1
|
@@ -1,209 +1,209 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* esm-hmr/client.js
|
|
3
|
-
* A client-side implementation of the ESM-HMR spec, for reference.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
function debug(...args) {
|
|
7
|
-
console.log("[ESM-HMR]", ...args);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function reload() {
|
|
11
|
-
location.reload(true);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
let SOCKET_MESSAGE_QUEUE = [];
|
|
15
|
-
|
|
16
|
-
function _sendSocketMessage(msg) {
|
|
17
|
-
socket.send(JSON.stringify(msg));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
function sendSocketMessage(msg) {
|
|
21
|
-
if (socket.readyState !== socket.OPEN) {
|
|
22
|
-
SOCKET_MESSAGE_QUEUE.push(msg);
|
|
23
|
-
} else {
|
|
24
|
-
_sendSocketMessage(msg);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const socketURL =
|
|
29
|
-
window.HMR_WEBSOCKET_URL ||
|
|
30
|
-
(location.protocol === "http:" ? "ws://" : "wss://") + location.host + "/";
|
|
31
|
-
const socket = new WebSocket(socketURL, "esm-hmr");
|
|
32
|
-
|
|
33
|
-
socket.addEventListener("open", () => {
|
|
34
|
-
SOCKET_MESSAGE_QUEUE.forEach(_sendSocketMessage);
|
|
35
|
-
SOCKET_MESSAGE_QUEUE = [];
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
const REGISTERED_MODULES = {};
|
|
39
|
-
class HotModuleState {
|
|
40
|
-
constructor(id) {
|
|
41
|
-
this.id = id;
|
|
42
|
-
this.data = {};
|
|
43
|
-
this.isLocked = false;
|
|
44
|
-
this.isDeclined = false;
|
|
45
|
-
this.isAccepted = false;
|
|
46
|
-
this.acceptCallbacks = [];
|
|
47
|
-
this.disposeCallbacks = [];
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
lock() {
|
|
51
|
-
this.isLocked = true;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
dispose(callback) {
|
|
55
|
-
this.disposeCallbacks.push(callback);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
invalidate() {
|
|
59
|
-
reload();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
decline() {
|
|
63
|
-
this.isDeclined = true;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
accept(_deps = [], callback = true) {
|
|
67
|
-
if (this.isLocked) {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (!this.isAccepted) {
|
|
71
|
-
sendSocketMessage({ id: this.id, type: "hotAccept" });
|
|
72
|
-
this.isAccepted = true;
|
|
73
|
-
}
|
|
74
|
-
if (!Array.isArray(_deps)) {
|
|
75
|
-
callback = _deps || callback;
|
|
76
|
-
_deps = [];
|
|
77
|
-
}
|
|
78
|
-
if (callback === true) {
|
|
79
|
-
callback = () => {};
|
|
80
|
-
}
|
|
81
|
-
const deps = _deps.map((dep) => {
|
|
82
|
-
const ext = dep.split(".").pop();
|
|
83
|
-
if (!ext) {
|
|
84
|
-
dep += ".js";
|
|
85
|
-
} else if (ext !== "js") {
|
|
86
|
-
dep += ".proxy.js";
|
|
87
|
-
}
|
|
88
|
-
return new URL(dep, `${window.location.origin}${this.id}`).pathname;
|
|
89
|
-
});
|
|
90
|
-
this.acceptCallbacks.push({
|
|
91
|
-
deps,
|
|
92
|
-
callback,
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export function createHotContext(id) {
|
|
98
|
-
const normId = id.startsWith("/") ? id : "/" + id;
|
|
99
|
-
const existing = REGISTERED_MODULES[normId] || REGISTERED_MODULES[id];
|
|
100
|
-
if (existing) {
|
|
101
|
-
existing.isLocked = false;
|
|
102
|
-
return existing;
|
|
103
|
-
}
|
|
104
|
-
const state = new HotModuleState(normId);
|
|
105
|
-
REGISTERED_MODULES[normId] = state;
|
|
106
|
-
REGISTERED_MODULES[id] = state;
|
|
107
|
-
return state;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
async function applyUpdate(id) {
|
|
111
|
-
const normId = id.startsWith("/") ? id : "/" + id;
|
|
112
|
-
const state = REGISTERED_MODULES[normId] || REGISTERED_MODULES[id];
|
|
113
|
-
if (!state) {
|
|
114
|
-
return true;
|
|
115
|
-
}
|
|
116
|
-
if (state.isDeclined) {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const acceptCallbacks = state.acceptCallbacks;
|
|
121
|
-
const disposeCallbacks = state.disposeCallbacks;
|
|
122
|
-
state.disposeCallbacks = [];
|
|
123
|
-
state.data = {};
|
|
124
|
-
|
|
125
|
-
disposeCallbacks.forEach((callback) => callback());
|
|
126
|
-
|
|
127
|
-
const updateID = Date.now();
|
|
128
|
-
for (const { deps, callback: acceptCallback } of acceptCallbacks) {
|
|
129
|
-
const [module, ...depModules] = await Promise.all([
|
|
130
|
-
import(normId + `?mtime=${updateID}`),
|
|
131
|
-
...deps.map((d) => {
|
|
132
|
-
const depId = d.startsWith("/") ? d : "/" + d;
|
|
133
|
-
return import(depId + `?mtime=${updateID}`);
|
|
134
|
-
}),
|
|
135
|
-
]);
|
|
136
|
-
acceptCallback({ module, deps: depModules });
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
return true;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
socket.addEventListener("message", ({ data: _data }) => {
|
|
143
|
-
if (!_data) return;
|
|
144
|
-
|
|
145
|
-
const data = JSON.parse(_data);
|
|
146
|
-
if (data.type === "reload") {
|
|
147
|
-
reload();
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
if (data.type === "rsc-update") {
|
|
152
|
-
if (typeof window !== "undefined" && typeof window.__DINOU_ROUTER_REFRESH__ === "function") {
|
|
153
|
-
window.__DINOU_ROUTER_REFRESH__();
|
|
154
|
-
return;
|
|
155
|
-
}
|
|
156
|
-
reload();
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
if (
|
|
161
|
-
data.type === "style-update" ||
|
|
162
|
-
(data.type === "update" && data.url && (data.url.endsWith(".css") || data.url.includes("styles.css")))
|
|
163
|
-
) {
|
|
164
|
-
const targetUrl = data.url ? data.url.split("?")[0] : "";
|
|
165
|
-
const links = document.querySelectorAll('link[rel="stylesheet"]');
|
|
166
|
-
for (const link of links) {
|
|
167
|
-
const rawHref = link.getAttribute("href");
|
|
168
|
-
if (!rawHref) continue;
|
|
169
|
-
const cleanHref = rawHref.split("?")[0];
|
|
170
|
-
if (!targetUrl || cleanHref.endsWith(targetUrl) || targetUrl.endsWith(cleanHref) || cleanHref.includes("styles.css")) {
|
|
171
|
-
const nextUrl = new URL(link.href, window.location.origin);
|
|
172
|
-
nextUrl.searchParams.set("t", String(Date.now()));
|
|
173
|
-
link.href = nextUrl.href;
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
if (data.type !== "update") {
|
|
180
|
-
return;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
const tRecv = Date.now();
|
|
184
|
-
const isDebug = typeof window !== "undefined" && Boolean(window.__DINOU_DEBUG__);
|
|
185
|
-
|
|
186
|
-
if (isDebug) {
|
|
187
|
-
console.log(`⏱️ [BROWSER HMR] Received update for ${data.url} at ${new Date().toTimeString().slice(0, 8)}.${String(Date.now() % 1000).padStart(3, '0')}`);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
applyUpdate(data.url)
|
|
191
|
-
.then((ok) => {
|
|
192
|
-
if (!ok) {
|
|
193
|
-
if (isDebug) console.warn(`⏱️ [BROWSER HMR] applyUpdate returned false, falling back to full reload!`);
|
|
194
|
-
reload();
|
|
195
|
-
} else {
|
|
196
|
-
if (isDebug) {
|
|
197
|
-
console.log(`⏱️ [BROWSER HMR] Fast Refresh finished applying in ${Date.now() - tRecv}ms!`);
|
|
198
|
-
} else {
|
|
199
|
-
console.log(`[ESM-HMR] hot updated: ${data.url}`);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
})
|
|
203
|
-
.catch((err) => {
|
|
204
|
-
console.error(`[ESM-HMR] applyUpdate error:`, err);
|
|
205
|
-
reload();
|
|
206
|
-
});
|
|
207
|
-
});
|
|
208
|
-
|
|
209
|
-
debug("listening for file changes...");
|
|
1
|
+
/**
|
|
2
|
+
* esm-hmr/client.js
|
|
3
|
+
* A client-side implementation of the ESM-HMR spec, for reference.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
function debug(...args) {
|
|
7
|
+
console.log("[ESM-HMR]", ...args);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function reload() {
|
|
11
|
+
location.reload(true);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
let SOCKET_MESSAGE_QUEUE = [];
|
|
15
|
+
|
|
16
|
+
function _sendSocketMessage(msg) {
|
|
17
|
+
socket.send(JSON.stringify(msg));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function sendSocketMessage(msg) {
|
|
21
|
+
if (socket.readyState !== socket.OPEN) {
|
|
22
|
+
SOCKET_MESSAGE_QUEUE.push(msg);
|
|
23
|
+
} else {
|
|
24
|
+
_sendSocketMessage(msg);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const socketURL =
|
|
29
|
+
window.HMR_WEBSOCKET_URL ||
|
|
30
|
+
(location.protocol === "http:" ? "ws://" : "wss://") + location.host + "/";
|
|
31
|
+
const socket = new WebSocket(socketURL, "esm-hmr");
|
|
32
|
+
|
|
33
|
+
socket.addEventListener("open", () => {
|
|
34
|
+
SOCKET_MESSAGE_QUEUE.forEach(_sendSocketMessage);
|
|
35
|
+
SOCKET_MESSAGE_QUEUE = [];
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const REGISTERED_MODULES = {};
|
|
39
|
+
class HotModuleState {
|
|
40
|
+
constructor(id) {
|
|
41
|
+
this.id = id;
|
|
42
|
+
this.data = {};
|
|
43
|
+
this.isLocked = false;
|
|
44
|
+
this.isDeclined = false;
|
|
45
|
+
this.isAccepted = false;
|
|
46
|
+
this.acceptCallbacks = [];
|
|
47
|
+
this.disposeCallbacks = [];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
lock() {
|
|
51
|
+
this.isLocked = true;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
dispose(callback) {
|
|
55
|
+
this.disposeCallbacks.push(callback);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
invalidate() {
|
|
59
|
+
reload();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
decline() {
|
|
63
|
+
this.isDeclined = true;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
accept(_deps = [], callback = true) {
|
|
67
|
+
if (this.isLocked) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (!this.isAccepted) {
|
|
71
|
+
sendSocketMessage({ id: this.id, type: "hotAccept" });
|
|
72
|
+
this.isAccepted = true;
|
|
73
|
+
}
|
|
74
|
+
if (!Array.isArray(_deps)) {
|
|
75
|
+
callback = _deps || callback;
|
|
76
|
+
_deps = [];
|
|
77
|
+
}
|
|
78
|
+
if (callback === true) {
|
|
79
|
+
callback = () => {};
|
|
80
|
+
}
|
|
81
|
+
const deps = _deps.map((dep) => {
|
|
82
|
+
const ext = dep.split(".").pop();
|
|
83
|
+
if (!ext) {
|
|
84
|
+
dep += ".js";
|
|
85
|
+
} else if (ext !== "js") {
|
|
86
|
+
dep += ".proxy.js";
|
|
87
|
+
}
|
|
88
|
+
return new URL(dep, `${window.location.origin}${this.id}`).pathname;
|
|
89
|
+
});
|
|
90
|
+
this.acceptCallbacks.push({
|
|
91
|
+
deps,
|
|
92
|
+
callback,
|
|
93
|
+
});
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function createHotContext(id) {
|
|
98
|
+
const normId = id.startsWith("/") ? id : "/" + id;
|
|
99
|
+
const existing = REGISTERED_MODULES[normId] || REGISTERED_MODULES[id];
|
|
100
|
+
if (existing) {
|
|
101
|
+
existing.isLocked = false;
|
|
102
|
+
return existing;
|
|
103
|
+
}
|
|
104
|
+
const state = new HotModuleState(normId);
|
|
105
|
+
REGISTERED_MODULES[normId] = state;
|
|
106
|
+
REGISTERED_MODULES[id] = state;
|
|
107
|
+
return state;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
async function applyUpdate(id) {
|
|
111
|
+
const normId = id.startsWith("/") ? id : "/" + id;
|
|
112
|
+
const state = REGISTERED_MODULES[normId] || REGISTERED_MODULES[id];
|
|
113
|
+
if (!state) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
if (state.isDeclined) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const acceptCallbacks = state.acceptCallbacks;
|
|
121
|
+
const disposeCallbacks = state.disposeCallbacks;
|
|
122
|
+
state.disposeCallbacks = [];
|
|
123
|
+
state.data = {};
|
|
124
|
+
|
|
125
|
+
disposeCallbacks.forEach((callback) => callback());
|
|
126
|
+
|
|
127
|
+
const updateID = Date.now();
|
|
128
|
+
for (const { deps, callback: acceptCallback } of acceptCallbacks) {
|
|
129
|
+
const [module, ...depModules] = await Promise.all([
|
|
130
|
+
import(normId + `?mtime=${updateID}`),
|
|
131
|
+
...deps.map((d) => {
|
|
132
|
+
const depId = d.startsWith("/") ? d : "/" + d;
|
|
133
|
+
return import(depId + `?mtime=${updateID}`);
|
|
134
|
+
}),
|
|
135
|
+
]);
|
|
136
|
+
acceptCallback({ module, deps: depModules });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
socket.addEventListener("message", ({ data: _data }) => {
|
|
143
|
+
if (!_data) return;
|
|
144
|
+
|
|
145
|
+
const data = JSON.parse(_data);
|
|
146
|
+
if (data.type === "reload") {
|
|
147
|
+
reload();
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (data.type === "rsc-update") {
|
|
152
|
+
if (typeof window !== "undefined" && typeof window.__DINOU_ROUTER_REFRESH__ === "function") {
|
|
153
|
+
window.__DINOU_ROUTER_REFRESH__();
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
reload();
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
if (
|
|
161
|
+
data.type === "style-update" ||
|
|
162
|
+
(data.type === "update" && data.url && (data.url.endsWith(".css") || data.url.includes("styles.css")))
|
|
163
|
+
) {
|
|
164
|
+
const targetUrl = data.url ? data.url.split("?")[0] : "";
|
|
165
|
+
const links = document.querySelectorAll('link[rel="stylesheet"]');
|
|
166
|
+
for (const link of links) {
|
|
167
|
+
const rawHref = link.getAttribute("href");
|
|
168
|
+
if (!rawHref) continue;
|
|
169
|
+
const cleanHref = rawHref.split("?")[0];
|
|
170
|
+
if (!targetUrl || cleanHref.endsWith(targetUrl) || targetUrl.endsWith(cleanHref) || cleanHref.includes("styles.css")) {
|
|
171
|
+
const nextUrl = new URL(link.href, window.location.origin);
|
|
172
|
+
nextUrl.searchParams.set("t", String(Date.now()));
|
|
173
|
+
link.href = nextUrl.href;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (data.type !== "update") {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
const tRecv = Date.now();
|
|
184
|
+
const isDebug = typeof window !== "undefined" && Boolean(window.__DINOU_DEBUG__);
|
|
185
|
+
|
|
186
|
+
if (isDebug) {
|
|
187
|
+
console.log(`⏱️ [BROWSER HMR] Received update for ${data.url} at ${new Date().toTimeString().slice(0, 8)}.${String(Date.now() % 1000).padStart(3, '0')}`);
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
applyUpdate(data.url)
|
|
191
|
+
.then((ok) => {
|
|
192
|
+
if (!ok) {
|
|
193
|
+
if (isDebug) console.warn(`⏱️ [BROWSER HMR] applyUpdate returned false, falling back to full reload!`);
|
|
194
|
+
reload();
|
|
195
|
+
} else {
|
|
196
|
+
if (isDebug) {
|
|
197
|
+
console.log(`⏱️ [BROWSER HMR] Fast Refresh finished applying in ${Date.now() - tRecv}ms!`);
|
|
198
|
+
} else {
|
|
199
|
+
console.log(`[ESM-HMR] hot updated: ${data.url}`);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
})
|
|
203
|
+
.catch((err) => {
|
|
204
|
+
console.error(`[ESM-HMR] applyUpdate error:`, err);
|
|
205
|
+
reload();
|
|
206
|
+
});
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
debug("listening for file changes...");
|
package/dinou/index.d.ts
CHANGED
|
@@ -588,15 +588,16 @@ export declare function useRouter(): {
|
|
|
588
588
|
* @param slotId - The slot identifier or tag.
|
|
589
589
|
* @param options - Optional configuration ({ fresh?: boolean }).
|
|
590
590
|
*/
|
|
591
|
-
refreshSlot: (slotId: string, options?: { fresh?: boolean }) => void
|
|
591
|
+
refreshSlot: (slotId: string, options?: { fresh?: boolean }) => Promise<void>;
|
|
592
592
|
};
|
|
593
593
|
|
|
594
594
|
/**
|
|
595
595
|
* Programmatically refreshes a specific DinouCacheSlot in the browser without reloading the page.
|
|
596
|
+
* Returns a Promise that resolves once matching slot refreshes have settled.
|
|
596
597
|
* @param slotId - The slot identifier or tag to refresh.
|
|
597
598
|
* @param options - Optional configuration ({ fresh?: boolean }).
|
|
598
599
|
*/
|
|
599
|
-
export declare function refreshSlot(slotId: string, options?: { fresh?: boolean }): void
|
|
600
|
+
export declare function refreshSlot(slotId: string, options?: { fresh?: boolean }): Promise<void>;
|
|
600
601
|
|
|
601
602
|
/**
|
|
602
603
|
* A Client Component hook that returns true if a navigation (SPA transition) is currently in progress.
|