@cloudwerk/vite-plugin 0.8.1 → 0.15.17

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.
Files changed (2) hide show
  1. package/dist/index.js +33 -6
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -190,15 +190,27 @@ function generateServerEntry(manifest, scanResult, options, entryOptions) {
190
190
  cssLinksCode = `const CSS_LINKS = ''`;
191
191
  }
192
192
  const viteClientScript = options.isProduction ? "" : '<script type="module" src="/@vite/client"></script>';
193
+ const messageChannelPolyfill = rendererName === "react" ? `// Polyfill MessageChannel for Cloudflare Workers upload validation phase
194
+ // Workers provide MessageChannel at request time, but not during script validation
195
+ if (typeof globalThis.MessageChannel === 'undefined') {
196
+ globalThis.MessageChannel = class MessageChannel {
197
+ constructor() {
198
+ this.port1 = { onmessage: null, postMessage() {}, close() {}, start() {} }
199
+ this.port2 = { onmessage: null, postMessage() {}, close() {}, start() {} }
200
+ }
201
+ }
202
+ }
203
+
204
+ ` : "";
193
205
  return `/**
194
206
  * Generated Cloudwerk Server Entry
195
207
  * This file is auto-generated by @cloudwerk/vite-plugin - do not edit
196
208
  */
197
209
 
198
- import { Hono } from 'hono'
210
+ ${messageChannelPolyfill}import { Hono } from 'hono'
199
211
  import { ssgParams } from 'hono/ssg'
200
212
  import { contextMiddleware, createHandlerAdapter, createMiddlewareAdapter, setRouteConfig, NotFoundError, RedirectError } from '@cloudwerk/core/runtime'
201
- import { setActiveRenderer${rendererName === "react" ? ", initReactRenderer" : ""} } from '@cloudwerk/ui'
213
+ import { setActiveRenderer, getActiveRenderer${rendererName === "react" ? ", initReactRenderer" : ""} } from '@cloudwerk/ui'
202
214
 
203
215
  // Page and Route Imports
204
216
  ${imports.join("\n")}
@@ -462,9 +474,9 @@ function registerPage(app, pattern, pageModule, layoutModules, middlewareModules
462
474
  */
463
475
  async function renderWithHydration(element, status = 200, routeId, pageProps, layoutData) {
464
476
  // Render element to HTML string using the active renderer
465
- ${rendererName === "react" ? `// React: use renderToString from react-dom/server
466
- const { renderToString } = await import('react-dom/server')
467
- let html = '<!DOCTYPE html>' + renderToString(element)` : `// Hono JSX elements have toString() for synchronous rendering
477
+ ${rendererName === "react" ? `// React: use the active renderer to render to HTML
478
+ const rendererResponse = await getActiveRenderer().render(element, { doctype: false })
479
+ let html = '<!DOCTYPE html>' + await rendererResponse.text()` : `// Hono JSX elements have toString() for synchronous rendering
468
480
  let html = '<!DOCTYPE html>' + String(element)`}
469
481
 
470
482
  // Inject CSS links before </head> if present
@@ -557,6 +569,13 @@ app.use('*', async (c, next) => {
557
569
  return
558
570
  }
559
571
 
572
+ // Skip static asset serving during SSG \u2014 the ASSETS binding from getPlatformProxy
573
+ // is not a real Workers Static Assets binding and does not support fetch(Request)
574
+ if (c.env?.HONO_SSG_CONTEXT) {
575
+ await next()
576
+ return
577
+ }
578
+
560
579
  // Only serve static assets for GET/HEAD requests
561
580
  // Other methods (POST, PUT, etc.) should go directly to route handlers
562
581
  // to avoid consuming the request body
@@ -567,7 +586,15 @@ app.use('*', async (c, next) => {
567
586
  }
568
587
 
569
588
  // Try to serve the request as a static asset
570
- const response = await c.env.ASSETS.fetch(c.req.raw)
589
+ let response
590
+ try {
591
+ response = await c.env.ASSETS.fetch(c.req.raw)
592
+ } catch {
593
+ // ASSETS.fetch can fail during SSG or when the binding is a proxy
594
+ // that doesn't support fetch(Request) \u2014 fall through to routes
595
+ await next()
596
+ return
597
+ }
571
598
 
572
599
  // If asset found (not 404), return it with cache headers
573
600
  if (response.status !== 404) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cloudwerk/vite-plugin",
3
- "version": "0.8.1",
3
+ "version": "0.15.17",
4
4
  "description": "Vite plugin for Cloudwerk file-based routing with virtual entry generation",
5
5
  "repository": {
6
6
  "type": "git",
@@ -19,8 +19,8 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "@swc/core": "^1.3.100",
22
- "@cloudwerk/core": "^0.15.3",
23
- "@cloudwerk/ui": "^0.15.6"
22
+ "@cloudwerk/ui": "^0.15.17",
23
+ "@cloudwerk/core": "^0.15.3"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "vite": "^5.0.0 || ^6.0.0 || ^7.0.0",