feat: sub-path (basePath) deployment support + oversized message guard - #370
Open
windli2018 wants to merge 4 commits into
Open
feat: sub-path (basePath) deployment support + oversized message guard#370windli2018 wants to merge 4 commits into
windli2018 wants to merge 4 commits into
Conversation
- next.config.ts: basePath from PI_WEB_BASE_PATH env; expose NEXT_PUBLIC_BASE_PATH; allow public hostnames in allowedDevOrigins for dev HMR through a reverse proxy - lib/base-path.ts: withBasePath/apiUrl helpers - client fetch/EventSource call sites prefixed via apiUrl() so all API traffic follows the base path - layout.tsx manifest/icons, PwaRegistration scope, public/sw.js made base-path aware (scope-derived URLs) - no behavior change when PI_WEB_BASE_PATH is unset (root deployment)
Multi-hundred-KB messages (pasted HAR/log dumps) freeze the browser because react-markdown + KaTeX + syntax highlighting run on the entire payload. SafeMarkdownBody renders such messages as a click-to-reveal plain-text <pre> instead; applies to user messages and assistant text blocks. i18n: en/zh-CN.
…th-aware - next.config: ignore PI_WEB_BASE_PATH during production builds unless PI_WEB_BUILD_BASEPATH=1 (builds spawned from the dev-server env otherwise bake a /dev asset prefix into .next and break the root deployment) - app/manifest.ts: start_url/scope/icons via withBasePath for sub-path PWA - .gitignore: ignore .playwright-mcp test artifacts
The models list endpoint was still hardcoded, so with a sub-path deployment (/dev) GET /api/models 404'd and the model selector failed to load.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two independent improvements for the pi-web web UI:
1. Sub-path (basePath) deployment support
Allow pi-web to be served under a URL prefix (e.g.
https://host/dev/) viaPI_WEB_BASE_PATH, on top of Next.jsbasePath.next.config.ts: readPI_WEB_BASE_PATHenv →basePath+ exposeNEXT_PUBLIC_BASE_PATH; production builds ignore it unlessPI_WEB_BUILD_BASEPATH=1so a build spawned from the dev-server env can never bake a/devasset prefix into.nextlib/base-path.ts:withBasePath()/apiUrl()helpersfetch()/EventSource()API calls are prefixed throughapiUrl()(AppShell, ChatInput, DirectoryPicker, ExportDialog, FileExplorer, FileViewer, MarkdownBody, MessageView, ModelsConfig, PluginsConfig, QuoteReplyPopover, SessionSidebar, SkillsConfig, useAgentSession, agent-client)app/layout.tsx+app/manifest.ts: icons / start_url / scope basePath-awarecomponents/PwaRegistration.tsx+public/sw.js: service worker scope-awareallowedDevOriginsextended (dev HMR through a reverse proxy)Backwards compatible: with
PI_WEB_BASE_PATHunset, all helpers return the original paths — root deployment is unchanged.2. Guard oversized message rendering against browser freeze
Messages > 100 KB (e.g. pasted HAR/log dumps — one session had a 610 KB message) froze the browser because react-markdown + KaTeX + syntax highlighting processed the whole payload.
components/MessageView.tsx: newSafeMarkdownBody— oversized messages render as a click-to-reveal plain-text<pre>(max-height scroll), markdown pipeline skippedi18n.largeMessageReveal(en / zh-CN)Testing
tsc --noEmitclean; eslint clean on changed filesPI_WEB_BASE_PATH=/dev: page,/dev/api/*, manifest (start_url=/dev/,scope=/dev/),/dev/_next/*asset prefix — all verified via curl + real Firefox session (0 console errors)PI_WEB_BASE_PATH=/dev+NODE_ENV=productionprints the ignore warning and produces a clean root deployment (no/devasset prefix)