one 1.1.495 → 1.1.497
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/dist/cjs/vite/plugins/SSRCSSPlugin.cjs +20 -19
- package/dist/cjs/vite/plugins/SSRCSSPlugin.js +15 -14
- package/dist/cjs/vite/plugins/SSRCSSPlugin.js.map +1 -1
- package/dist/cjs/vite/plugins/SSRCSSPlugin.native.js +16 -27
- package/dist/cjs/vite/plugins/SSRCSSPlugin.native.js.map +2 -2
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.cjs +1 -1
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js +67 -64
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js +1 -1
- package/dist/cjs/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
- package/dist/esm/vite/plugins/SSRCSSPlugin.js +15 -14
- package/dist/esm/vite/plugins/SSRCSSPlugin.js.map +1 -1
- package/dist/esm/vite/plugins/SSRCSSPlugin.mjs +19 -18
- package/dist/esm/vite/plugins/SSRCSSPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/SSRCSSPlugin.native.js +22 -35
- package/dist/esm/vite/plugins/SSRCSSPlugin.native.js.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.js +67 -64
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.js.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.mjs.map +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js +1 -1
- package/dist/esm/vite/plugins/fileSystemRouterPlugin.native.js.map +1 -1
- package/package.json +8 -8
- package/src/vite/plugins/SSRCSSPlugin.ts +19 -28
- package/src/vite/plugins/fileSystemRouterPlugin.tsx +105 -102
- package/types/vite/plugins/SSRCSSPlugin.d.ts.map +1 -1
- package/types/vite/plugins/fileSystemRouterPlugin.d.ts.map +1 -1
@@ -95,6 +95,8 @@ function invalidateModule(server: ViteDevServer, id: string) {
|
|
95
95
|
// https://github.com/vikejs/vike/blob/f9a91f3c47cab9c2871526ef714cc0f87a41fda0/vike/node/runtime/renderPage/getPageAssets/retrieveAssetsDev.ts
|
96
96
|
|
97
97
|
export async function collectStyle(server: ViteDevServer, entries: string[]) {
|
98
|
+
const { transform } = await import('lightningcss')
|
99
|
+
|
98
100
|
const urls = await collectStyleUrls(server, entries)
|
99
101
|
const codes = await Promise.all(
|
100
102
|
urls.map(async (url) => {
|
@@ -103,7 +105,6 @@ export async function collectStyle(server: ViteDevServer, entries: string[]) {
|
|
103
105
|
const prefix = `/* [collectStyle] ${url} */`
|
104
106
|
|
105
107
|
try {
|
106
|
-
const { transform } = await import('lightningcss')
|
107
108
|
const buffer = Buffer.from(code)
|
108
109
|
const codeOut = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
109
110
|
|
@@ -113,18 +114,6 @@ export async function collectStyle(server: ViteDevServer, entries: string[]) {
|
|
113
114
|
...server.config.css.lightningcss,
|
114
115
|
}).code.toString()
|
115
116
|
|
116
|
-
if (process.env.ONE_DEBUG_CSS) {
|
117
|
-
console.info(`Got CSS`, processed)
|
118
|
-
}
|
119
|
-
|
120
|
-
if (process.env.ONE_DEDUPE_CSS) {
|
121
|
-
processed = dedupeCSS(processed)
|
122
|
-
}
|
123
|
-
|
124
|
-
if (process.env.ONE_DEBUG_CSS) {
|
125
|
-
console.info(`Got CSS after dedupe`, processed)
|
126
|
-
}
|
127
|
-
|
128
117
|
return [prefix, processed]
|
129
118
|
} catch (err) {
|
130
119
|
console.error(` [one] Error post-processing CSS, leaving un-processed: ${err}`)
|
@@ -132,7 +121,23 @@ export async function collectStyle(server: ViteDevServer, entries: string[]) {
|
|
132
121
|
}
|
133
122
|
})
|
134
123
|
)
|
135
|
-
|
124
|
+
|
125
|
+
let out = codes.flat().filter(Boolean).join('\n\n')
|
126
|
+
|
127
|
+
try {
|
128
|
+
// run once more at the end to de-dupe!
|
129
|
+
const buffer = Buffer.from(out)
|
130
|
+
const codeOut = new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
131
|
+
out = transform({
|
132
|
+
filename: 'code.css',
|
133
|
+
code: codeOut,
|
134
|
+
...server.config.css.lightningcss,
|
135
|
+
}).code.toString()
|
136
|
+
} catch (err) {
|
137
|
+
console.error(` [one] Error post-processing merged CSS, leaving un-processed`)
|
138
|
+
}
|
139
|
+
|
140
|
+
return out
|
136
141
|
}
|
137
142
|
|
138
143
|
async function collectStyleUrls(server: ViteDevServer, entries: string[]): Promise<string[]> {
|
@@ -163,17 +168,3 @@ async function collectStyleUrls(server: ViteDevServer, entries: string[]): Promi
|
|
163
168
|
|
164
169
|
// cf. https://github.com/vitejs/vite/blob/d6bde8b03d433778aaed62afc2be0630c8131908/packages/vite/src/node/constants.ts#L49C23-L50
|
165
170
|
const CSS_LANGS_RE = /\.(css|less|sass|scss|styl|stylus|pcss|postcss|sss)(?:$|\?)/
|
166
|
-
|
167
|
-
function dedupeCSS(css: string): string {
|
168
|
-
const lines = css.split('\n')
|
169
|
-
const uniqueLines = new Set<string>()
|
170
|
-
|
171
|
-
for (const line of lines) {
|
172
|
-
const trimmedLine = line.trim()
|
173
|
-
if (trimmedLine) {
|
174
|
-
uniqueLines.add(trimmedLine)
|
175
|
-
}
|
176
|
-
}
|
177
|
-
|
178
|
-
return Array.from(uniqueLines).join('\n')
|
179
|
-
}
|
@@ -32,17 +32,18 @@ export function createFileSystemRouterPlugin(options: One.PluginOptions): Plugin
|
|
32
32
|
|
33
33
|
function createRequestHandler() {
|
34
34
|
const routerRoot = getRouterRootFromOneOptions(options)
|
35
|
-
return createHandleRequest(
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
route.
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
35
|
+
return createHandleRequest(
|
36
|
+
{
|
37
|
+
async handlePage({ route, url, loaderProps }) {
|
38
|
+
console.info(
|
39
|
+
` ⓵ [${route.type}] ${url} resolved to ${
|
40
|
+
route.isNotFound ? '‼️ 404 not found' : `app/${route.file.slice(2)}`
|
41
|
+
}`
|
42
|
+
)
|
43
|
+
|
44
|
+
if (route.type === 'spa') {
|
45
|
+
// render just the layouts? route.layouts
|
46
|
+
return `<html><head>
|
46
47
|
${getSpaHeaderElements({ serverContext: { mode: 'spa' } })}
|
47
48
|
<script type="module">
|
48
49
|
import { injectIntoGlobalHook } from "/@react-refresh";
|
@@ -53,76 +54,76 @@ export function createFileSystemRouterPlugin(options: One.PluginOptions): Plugin
|
|
53
54
|
<script type="module" src="/@vite/client" async=""></script>
|
54
55
|
<script type="module" src="/@id/__x00__virtual:one-entry" async=""></script>
|
55
56
|
</head></html>`
|
56
|
-
|
57
|
-
|
58
|
-
if (renderPromise) {
|
59
|
-
await renderPromise
|
60
|
-
}
|
57
|
+
}
|
61
58
|
|
62
|
-
|
63
|
-
|
59
|
+
if (renderPromise) {
|
60
|
+
await renderPromise
|
61
|
+
}
|
64
62
|
|
65
|
-
|
66
|
-
|
67
|
-
runner.clearCache()
|
63
|
+
const { promise, resolve } = promiseWithResolvers<void>()
|
64
|
+
renderPromise = promise
|
68
65
|
|
69
|
-
|
66
|
+
try {
|
67
|
+
const routeFile = join(routerRoot, route.file)
|
68
|
+
runner.clearCache()
|
70
69
|
|
71
|
-
|
72
|
-
const loaderData = await exported.loader?.(loaderProps)
|
70
|
+
globalThis['__vxrnresetState']?.()
|
73
71
|
|
74
|
-
|
75
|
-
|
72
|
+
const exported = routeFile === '' ? {} : await runner.import(routeFile)
|
73
|
+
const loaderData = await exported.loader?.(loaderProps)
|
76
74
|
|
77
|
-
|
75
|
+
// biome-ignore lint/security/noGlobalEval: <explanation>
|
76
|
+
eval(`process.env.TAMAGUI_IS_SERVER = '1'`)
|
78
77
|
|
79
|
-
|
78
|
+
const entry = await runner.import(virtualEntryId)
|
80
79
|
|
81
|
-
|
82
|
-
loaderData,
|
83
|
-
loaderProps,
|
84
|
-
})
|
80
|
+
const render = entry.default.render as (props: RenderAppProps) => any
|
85
81
|
|
86
|
-
|
82
|
+
setServerContext({
|
83
|
+
loaderData,
|
84
|
+
loaderProps,
|
85
|
+
})
|
87
86
|
|
88
|
-
|
87
|
+
LoaderDataCache[route.file] = loaderData
|
89
88
|
|
90
|
-
|
91
|
-
mode: route.type === 'ssg' ? 'ssg' : route.type === 'ssr' ? 'ssr' : 'spa',
|
92
|
-
loaderData,
|
93
|
-
loaderProps,
|
94
|
-
path: loaderProps?.path || '/',
|
95
|
-
preloads,
|
96
|
-
})
|
89
|
+
const is404 = route.isNotFound || !exported.default
|
97
90
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
91
|
+
const html = await render({
|
92
|
+
mode: route.type === 'ssg' ? 'ssg' : route.type === 'ssr' ? 'ssr' : 'spa',
|
93
|
+
loaderData,
|
94
|
+
loaderProps,
|
95
|
+
path: loaderProps?.path || '/',
|
96
|
+
preloads,
|
102
97
|
})
|
103
|
-
}
|
104
98
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
?
|
99
|
+
if (is404) {
|
100
|
+
return new Response(html, {
|
101
|
+
status: 404,
|
102
|
+
headers: { 'Content-Type': 'text/html' },
|
103
|
+
})
|
104
|
+
}
|
105
|
+
|
106
|
+
return html
|
107
|
+
} catch (err) {
|
108
|
+
console.error(`SSR error while loading file ${route.file} from URL ${url.href}\n`, err)
|
109
|
+
const title = `Error rendering ${url.pathname} on server`
|
110
|
+
const message = err instanceof Error ? err.message : `${err}`
|
111
|
+
const stack = err instanceof Error ? err.stack || '' : ''
|
112
|
+
|
113
|
+
const isDuplicateReactError =
|
114
|
+
/at (useEffect|useState|useReducer|useContext|useLayoutEffect)\s*\(.*?react\.development\.js/g.test(
|
115
|
+
stack
|
116
|
+
)
|
117
|
+
const subMessage = isDuplicateReactError
|
118
|
+
? `
|
118
119
|
<h2>Duplicate React Error</h2>
|
119
120
|
<p style="font-size: 18px; line-height: 24px; max-width: 850px;">Note: These types of errors happen during SSR because One needs all dependencies that use React to be optimized. Find the dependency on the line after the react.development.js line below to find the failing dependency. So long as that dependency has "react" as a sub-dependency, you can add it to your package.json and One will optimize it automatically. If it doesn't list it properly, you can fix this manually by changing your vite.config.ts One plugin to add "one({ deps: { depName: true })" so One optimizes depName.</p>
|
120
121
|
`
|
121
|
-
|
122
|
+
: ``
|
122
123
|
|
123
|
-
|
124
|
+
console.error(`${title}\n ${message}\n\n${stack}\n`)
|
124
125
|
|
125
|
-
|
126
|
+
return `
|
126
127
|
<html>
|
127
128
|
<body style="background: #000; color: #fff; padding: 5%; font-family: monospace; line-height: 2rem;">
|
128
129
|
<h1 style="display: inline-flex; background: red; color: white; padding: 5px; margin: -5px;">${title}</h1>
|
@@ -138,58 +139,60 @@ export function createFileSystemRouterPlugin(options: One.PluginOptions): Plugin
|
|
138
139
|
</body>
|
139
140
|
</html>
|
140
141
|
`
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
142
|
+
} finally {
|
143
|
+
resolve()
|
144
|
+
}
|
145
|
+
},
|
145
146
|
|
146
|
-
|
147
|
-
|
147
|
+
async handleLoader({ request, route, url, loaderProps }) {
|
148
|
+
const routeFile = join(routerRoot, route.file)
|
148
149
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
150
|
+
// this will remove all loaders
|
151
|
+
let transformedJS = (await server.transformRequest(routeFile))?.code
|
152
|
+
if (!transformedJS) {
|
153
|
+
throw new Error(`No transformed js returned`)
|
154
|
+
}
|
154
155
|
|
155
|
-
|
156
|
-
|
156
|
+
const exported = await runner.import(routeFile)
|
157
|
+
const loaderData = await exported.loader?.(loaderProps)
|
157
158
|
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
159
|
+
if (loaderData) {
|
160
|
+
// add loader back in!
|
161
|
+
transformedJS = replaceLoader({
|
162
|
+
code: transformedJS,
|
163
|
+
loaderData,
|
164
|
+
})
|
165
|
+
}
|
165
166
|
|
166
|
-
|
167
|
+
const platform = url.searchParams.get('platform')
|
167
168
|
|
168
|
-
|
169
|
-
|
169
|
+
if (platform === 'ios' || platform === 'android') {
|
170
|
+
// Need to transpile to CommonJS for React Native
|
170
171
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
172
|
+
const environment = server.environments[platform || '']
|
173
|
+
if (!environment) {
|
174
|
+
throw new Error(`[handleLoader] No Vite environment found for platform '${platform}'`)
|
175
|
+
}
|
175
176
|
|
176
|
-
|
177
|
-
|
177
|
+
// [3] Just use a simple function to return the loader data for now.
|
178
|
+
const nativeTransformedJS = `exports.loader = () => (${JSON.stringify(loaderData)});`
|
178
179
|
|
179
|
-
|
180
|
-
|
180
|
+
return nativeTransformedJS
|
181
|
+
}
|
181
182
|
|
182
|
-
|
183
|
-
|
183
|
+
return transformedJS
|
184
|
+
},
|
184
185
|
|
185
|
-
|
186
|
-
|
187
|
-
|
186
|
+
async handleAPI({ route }) {
|
187
|
+
return await runner.import(join(routerRoot, route.file))
|
188
|
+
},
|
188
189
|
|
189
|
-
|
190
|
-
|
190
|
+
async loadMiddleware(route) {
|
191
|
+
return await runner.import(join(routerRoot, route.contextKey))
|
192
|
+
},
|
191
193
|
},
|
192
|
-
|
194
|
+
{ routerRoot }
|
195
|
+
)
|
193
196
|
}
|
194
197
|
|
195
198
|
return {
|
@@ -412,7 +415,7 @@ export function createFileSystemRouterPlugin(options: One.PluginOptions): Plugin
|
|
412
415
|
res.end()
|
413
416
|
return
|
414
417
|
} catch (error) {
|
415
|
-
console.error(`
|
418
|
+
console.error(`[one] routing error ${req.url}: ${error}`)
|
416
419
|
// Forward the error to Vite
|
417
420
|
next(error)
|
418
421
|
}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"SSRCSSPlugin.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/SSRCSSPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAKjD,wBAAgB,YAAY,CAAC,UAAU,EAAE;IAAE,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,MAAM,CA8EtE;AAaD,wBAAsB,YAAY,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,
|
1
|
+
{"version":3,"file":"SSRCSSPlugin.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/SSRCSSPlugin.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,MAAM,CAAA;AAKjD,wBAAgB,YAAY,CAAC,UAAU,EAAE;IAAE,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,GAAG,MAAM,CA8EtE;AAaD,wBAAsB,YAAY,CAAC,MAAM,EAAE,aAAa,EAAE,OAAO,EAAE,MAAM,EAAE,mBA4C1E"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"fileSystemRouterPlugin.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/fileSystemRouterPlugin.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAW,MAAM,EAAiB,MAAM,MAAM,CAAA;AAW1D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAQ3C,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,GAAG,CAAC,aAAa,GAAG,MAAM,
|
1
|
+
{"version":3,"file":"fileSystemRouterPlugin.d.ts","sourceRoot":"","sources":["../../../src/vite/plugins/fileSystemRouterPlugin.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAW,MAAM,EAAiB,MAAM,MAAM,CAAA;AAW1D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAQ3C,wBAAgB,4BAA4B,CAAC,OAAO,EAAE,GAAG,CAAC,aAAa,GAAG,MAAM,CAyZ/E"}
|