Title: feat(hub): let buildHub bake an already-assembled context (reuse in Vite DevTools) · Issue #347 · devframes/devframe · GitHub
Open Graph Title: feat(hub): let buildHub bake an already-assembled context (reuse in Vite DevTools) · Issue #347 · devframes/devframe
X Title: feat(hub): let buildHub bake an already-assembled context (reuse in Vite DevTools) · Issue #347 · devframes/devframe
Description: What buildHub (@devframes/hub/build, #339) bakes a whole static hub — but it owns the entire pipeline: it creates its own createHubContext({ mode: 'build' }), mounts devframes from a devframes/configure input, then does the baking (stati...
Open Graph Description: What buildHub (@devframes/hub/build, #339) bakes a whole static hub — but it owns the entire pipeline: it creates its own createHubContext({ mode: 'build' }), mounts devframes from a devframes/conf...
X Description: What buildHub (@devframes/hub/build, #339) bakes a whole static hub — but it owns the entire pipeline: it creates its own createHubContext({ mode: 'build' }), mounts devframes from a devfra...
Opengraph URL: https://github.com/devframes/devframe/issues/347
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"feat(hub): let buildHub bake an already-assembled context (reuse in Vite DevTools)","articleBody":"## What\n\n`buildHub` (`@devframes/hub/build`, #339) bakes a whole static hub — but it **owns the entire pipeline**: it creates its own `createHubContext({ mode: 'build' })`, mounts devframes from a `devframes`/`configure` input, then does the baking (static-dir copy, renderer manifest, UI artifacts, `__client-imports.js`, `__index.json`, hub + per-frame `__connection.json`, and the RPC dump).\n\nVite DevTools (`@vitejs/devtools` + `@vitejs/devtools-kit`) can't feed it that way, so today it **re-implements the whole baker by hand** (`packages/core/src/node/build-static.ts`) and drifts out of sync with upstream — e.g. the 0.9.10 `collectStaticRpcDump` format change (files became `{ serialization, fnName, data }` wrappers with per-file structured-clone/json encoding) silently broke our hand-rolled `JSON.stringify(data)` writer until we switched to the now-shared `writeStaticRpcDump`.\n\nWe'd like to reuse `buildHub`'s baking instead of shadowing it. A few things block that.\n\n## Why `buildHub`'s own-context model doesn't fit\n\nVite DevTools assembles its context differently from a plain hub:\n\n1. **Kit-augmented context.** It builds via `createKitContext` (wraps `createHubContext`) so the context carries Vite-specific slots (`viteConfig`/`viteServer`) that the integrations' `setup(ctx)` hooks read. `buildHub`'s internal `createHubContext(...)` produces a plain hub context without them.\n2. **Devframes arrive as Vite plugins, not a `devframes` array.** Built-ins and user integrations are mounted by scanning `viteConfig.plugins` for a `.devtools.setup` hook and running it against the context — arbitrary Vite plugins, not `DevframeDefinition`s we can enumerate into `buildHub({ devframes })`.\n3. **Capability gating happens Vite-side** (`shouldSkipSetupByCapabilities` on `plugin.devtools.capabilities[mode]`), before mount.\n\nSo we need to create + mount the context ourselves and hand the *already-mounted* context to the baker.\n\n## Requests (roughly in priority order)\n\n1. **Expose the post-mount baker as a public function that takes an existing, already-mounted `DevframeHubContext`.** Something like `bakeHubStatic(ctx, { outDir, base, ui, renderers, name, version, pretty })` that runs exactly the tail of `buildHub` (renderer manifest → UI artifacts → `__client-imports.js` → `__index.json` → hub + per-frame `__connection.json` → `collectStaticRpcDump` + `writeStaticRpcDump`), **without** creating a context or mounting devframes. `buildHub` then becomes `createHubContext` + `mountDevframes` + `bakeHubStatic(ctx, opts)`. This single change unblocks us — we stop shadowing the whole file and inherit format/behaviour fixes for free.\n\n2. **Frame discovery from an externally-mounted context.** The baker needs the installed frames + their bases to write `__index.json` and per-frame `__connection.json`. In `buildHub` these come from `mountDevframes`' return value and `host.mountConnectionMeta`. For a context mounted by the caller, please expose a public way to enumerate mounted frames/bases (e.g. `ctx.frames`, or via `getInternalContext`) so the baker can emit the index + per-frame metas it did not mount itself. (Today our hand-rolled builder writes only a single hub `__connection.json` and no `__index.json`, so a frame SPA loaded standalone can't find the shared dump — the exact gap #339 fixed for `buildHub`.)\n\n3. **Materialize `views.buildStaticDirs` from the provided context.** In build mode the kit host's `mountStatic` is a no-op (\"baked into build output by createBuild\"), so statics registered via `views.hostStatic` are only reachable through `ctx.views.buildStaticDirs` (each `{ baseUrl, source }`, some remote-asset sources needing `resolveStaticAssetsSource(...).materialize(dir)`). `buildHub` copies statics as a side effect of its own H3 host's `mount` during mounting; the extracted baker should instead iterate the provided context's `views.buildStaticDirs` so an externally-mounted context's statics get copied.\n\n4. **Don't unconditionally `rm -rf` `outDir`.** `buildHub` does `if (existsSync(outDir)) await fs.rm(outDir, { recursive: true })`. When baking into an existing app build output (the `@devframes/vite/hub` `build: true` case, and our `build.withApp`), the devtools subtree lives alongside the app's own `dist/`. A `clean?: boolean` opt-out (default keeping today's behaviour) would make it safe to point the baker at a shared directory.\n\n## Alternative (smaller scope)\n\nIf extracting a public baker is too big, publishing the internal helpers `buildHub` composes — `mountDevframes`, `renderClientImportsModule`, `resolveRendererRegistrations`, and the `__index.json` / connection-meta writers (currently private in the `assemble` chunk; only `createHubContext` and `buildHub` are public from `@devframes/hub/node` and `@devframes/hub/build`) — would at least let downstreams compose their own baker without copy-pasting upstream. The extracted `bakeHubStatic(ctx, opts)` is the cleaner outcome, though.\n\n## Context\n\n- `buildHub`: `packages/hub/src/node/build.ts` (from #339)\n- Downstream hand-rolled equivalent we want to delete: `vitejs/devtools` `packages/core/src/node/build-static.ts`\n\n---\n\nCreated with the help of an agent.\n","author":{"url":"https://github.com/antfubot","@type":"Person","name":"antfubot"},"datePublished":"2026-09-03T12:34:27Z","url":"https://github.com/devframes/devframe/issues/347"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react-reconciler,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@d5750093facf |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:ff9f3370-c570-ecf7-0aff-01c1ac9bb456 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C258:35E137:50CDC:6D899:6AFB842C |
| html-safe-nonce | 7f60ce505578e42084f529e20a6e00df8f2862a538b7932b7e02433b5c887bf1 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMjU4OjM1RTEzNzo1MENEQzo2RDg5OTo2QUZCODQyQyIsInZpc2l0b3JfaWQiOiI4NTkxMDE2NDU3NDAyMDI1MDA0IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8e747d909d440bbb590915287df715aa9e4a6cd4bf4a583368b9600084ad2417 |
| hovercard-subject-tag | issue:5336677022 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/devframes/devframe/347/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3cbe2ea08c6ce98f4a3421ec03eb39f5b42314b023b93eb0ceff9db468d21b05/devframes/devframe/issues/347 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3cbe2ea08c6ce98f4a3421ec03eb39f5b42314b023b93eb0ceff9db468d21b05/devframes/devframe/issues/347 |
| og:image:alt | What buildHub (@devframes/hub/build, #339) bakes a whole static hub — but it owns the entire pipeline: it creates its own createHubContext({ mode: 'build' }), mounts devframes from a devframes/conf... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | antfubot |
| hostname | github.com |
| expected-hostname | github.com |
| None | ef32892d4269fb87b55e81cc4ba8d86e0f16aa28446ffbf46cba8be5179ab188 |
| turbo-cache-control | no-preview |
| go-import | github.com/devframes/devframe git https://github.com/devframes/devframe.git |
| octolytics-dimension-user_id | 279879373 |
| octolytics-dimension-user_login | devframes |
| octolytics-dimension-repository_id | 1231722386 |
| octolytics-dimension-repository_nwo | devframes/devframe |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 1231722386 |
| octolytics-dimension-repository_network_root_nwo | devframes/devframe |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | bc3703b4dcbe820d1284ef63c88b001c850be25e |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width