@tinvar/renderer 0.4.6 → 0.4.8
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/package.json +1 -1
- package/src/client-deps.js +25 -0
- package/src/dev-server.js +2 -0
package/package.json
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
// What the browser's dependency optimizer leaves alone in dev (ADR 0180).
|
|
2
|
+
//
|
|
3
|
+
// Vite bundles the packages the browser imports before it serves them.
|
|
4
|
+
// @tinvar/react's client components are client references, which the RSC
|
|
5
|
+
// plugin points the browser at by their own path; bundled into the
|
|
6
|
+
// browser's @tinvar/react as well, a page loaded both copies, each with its
|
|
7
|
+
// own React, and the first page of every new app failed with "Invalid hook
|
|
8
|
+
// call" until Vite reloaded it. The plugin says so, as "client component
|
|
9
|
+
// dependency is inconsistently optimized". Served as its own modules, the
|
|
10
|
+
// package loads once. What it imports, React alone, is optimized as before.
|
|
11
|
+
|
|
12
|
+
/** Served to the browser as their own modules, never optimized into a bundle. */
|
|
13
|
+
export const NOT_OPTIMIZED = ['@tinvar/react'];
|
|
14
|
+
|
|
15
|
+
/** @returns {import('vite').Plugin} */
|
|
16
|
+
export function clientDependencies() {
|
|
17
|
+
return {
|
|
18
|
+
name: 'tinvar:client-dependencies',
|
|
19
|
+
apply: 'serve',
|
|
20
|
+
configEnvironment(name) {
|
|
21
|
+
// Merged with the app's own: Vite concatenates the lists.
|
|
22
|
+
return name === 'client' ? { optimizeDeps: { exclude: [...NOT_OPTIMIZED] } } : undefined;
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
}
|
package/src/dev-server.js
CHANGED
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
viewsOf,
|
|
33
33
|
} from './vite.js';
|
|
34
34
|
|
|
35
|
+
import { clientDependencies } from './client-deps.js';
|
|
35
36
|
import { styleXDevStyles } from './stylex-dev.js';
|
|
36
37
|
export { assertDevelopment, DevServerRefused, PRODUCTION_MARKERS } from './dev-guard.js';
|
|
37
38
|
|
|
@@ -102,6 +103,7 @@ export async function createDevServer({
|
|
|
102
103
|
...(logLevel ? { logLevel } : {}),
|
|
103
104
|
plugins: [
|
|
104
105
|
styles,
|
|
106
|
+
clientDependencies(),
|
|
105
107
|
ignoreReplayedChanges(watchedFrom),
|
|
106
108
|
followRestarts(() => {
|
|
107
109
|
const waiting = listened;
|