mirror of
https://github.com/remorses/gpuix.git
synced 2026-10-29 03:04:52 +08:00
Build the browser chat entry as part of the documentation website's production build. The web build now emits a minified `chat.js` bundle and its Wasm asset into the website's ignored public directory, after rebuilding the native Wasm and React package so deployed output cannot use stale generated code. Keep the production destination fixed at `website/public/chat-example` rather than accepting a caller-controlled directory. The build clears that generated directory before bundling without allowing a malformed command to remove an arbitrary repository path. Serve the shared example HTML at `/chat-example/`, redirect the non-trailing slash form, and set COOP and COEP on the document. Those headers make the page cross-origin isolated, which the shared WebAssembly memory requires. Static JavaScript and Wasm stay same-origin under the same route prefix. Add an accessible loading screen while the browser downloads and initializes the renderer, then remove it after GPUIX mounts. The same shell remains usable for local browser development, while the production route swaps its TypeScript entry for the generated JavaScript asset. Ignore the generated website bundle and add a minor changeset for the new live example at https://gpuix.dev/chat-example/. Session: ses_fc04fcb1dffeooxK1KAopXSTAY
20 lines
718 B
TypeScript
20 lines
718 B
TypeScript
/** Browser entry for the full GPUIX chat example. */
|
|
|
|
import React from 'react'
|
|
import { render } from '@gpuix/react'
|
|
import { ChatApp } from './chat'
|
|
|
|
// Do NOT add `import.meta.hot.accept("./chat", ...)` here. Bun runs an
|
|
// importer's dependency-accept callback even when the imported module already
|
|
// self-accepted for React Fast Refresh, so the callback would remount the tree
|
|
// on top of a successful refresh and throw away every `useState`. When an edit
|
|
// is not a refresh boundary, Bun reloads the page, which is the right fallback.
|
|
render(<ChatApp includeSafeMdx />, {
|
|
title: 'GPUIX Chat',
|
|
width: 1180,
|
|
height: 820,
|
|
debugFrameOverlay: 'full',
|
|
})
|
|
|
|
document.getElementById('gpuix-loader')?.remove()
|