Skip to content

fix(app): support runtime base paths for subpath deployments#5969

Open
nutzlastfan wants to merge 3 commits into
OHIF:masterfrom
nutzlastfan:fix/runtime-base-path-subpath-deploy
Open

fix(app): support runtime base paths for subpath deployments#5969
nutzlastfan wants to merge 3 commits into
OHIF:masterfrom
nutzlastfan:fix/runtime-base-path-subpath-deploy

Conversation

@nutzlastfan
Copy link
Copy Markdown

@nutzlastfan nutzlastfan commented Apr 20, 2026

Context

This ports the runtime base-path work from a downstream OHIF 3.11 deployment into current upstream master.

The main issue is that a single build still assumes a fixed build-time PUBLIC_URL, which breaks chunk loading, dynamic extension imports, and PWA asset resolution when the viewer is mounted under a subpath instead of /.

Changes

  • add shared runtime public-path helpers in @ohif/core
  • set webpack public path at runtime before the app bootstraps
  • switch generated plugin imports to resolve non-HTTP assets through the runtime base path
  • make the PWA template emit relative asset paths and derive the base path in the HTML head
  • make manifest icon paths relative so they work under subpath deployments

Result

A single viewer build can resolve static assets and dynamic imports correctly when served from paths like /some-prefix/viewer/... instead of only from the site root.

Notes

  • This PR intentionally keeps the scope on runtime base-path handling.
  • I opened it as a draft because upstream may prefer a different bootstrap shape for the early base-path script.

Greptile Summary

This PR ports runtime base-path support from a downstream OHIF 3.11 deployment, enabling a single build to be served from any subpath (e.g. /some-prefix/viewer/) by resolving __webpack_public_path__, chunk loading, PWA assets, and dynamic extension imports at runtime rather than at build time. The approach is sound — the webpack publicPath: '' + runtime assignment pattern is correct, and placing setRuntimePublicPath as the first import in index.js ensures the public path is set before any dynamic chunk loading.

Confidence Score: 4/5

Safe to merge once the open heuristic bug (viewerIndex guard, already tracked in prior threads) is resolved; remaining new findings are P2

The two new P2 findings — raw TS source import in platform/app/src/utils/publicUrl.ts and the missing leading slash on historyApiFallback.index — are minor. The score is held at 4 rather than 5 because the viewerIndex >= 0 correctness bug discussed in prior threads (affecting /viewer/-prefixed deployments) remains unresolved across publicUrl.ts, index.html, and rollbar.html.

platform/core/src/utils/publicUrl.ts, platform/app/public/html-templates/index.html, platform/app/public/html-templates/rollbar.html — all share the unguarded viewerIndex >= 0 heuristic; platform/app/src/utils/publicUrl.ts — direct TS source import

Important Files Changed

Filename Overview
platform/core/src/utils/publicUrl.ts New canonical module for runtime base-path logic; contains the known viewerIndex >= 0 heuristic bug (already flagged in existing threads) that resolves to the wrong path when the deployment prefix itself starts with /viewer
platform/app/src/setRuntimePublicPath.js Sets __webpack_public_path__, window.__OHIF_BASE_PATH__, and window.PUBLIC_URL at boot; now correctly imports from @ohif/core and is the first import in index.js
platform/app/src/utils/publicUrl.ts New app-level utility wrapper; still imports from the raw ../../../core/src/utils/publicUrl TS source instead of @ohif/core, the same coupling that was fixed in setRuntimePublicPath.js
platform/app/public/html-templates/index.html Adds inline base-path bootstrap script that sets window.__OHIF_BASE_PATH__ and a <base> element before assets load; shares the known viewerIndex >= 0 bug with the canonical TS module
platform/app/public/html-templates/rollbar.html Verbatim copy of the same bootstrap script as index.html; inherits the same viewerIndex >= 0 heuristic issue
platform/app/.webpack/webpack.pwa.js Drops fixed PUBLIC_URL in favour of empty-string publicPath so runtime __webpack_public_path__ takes over; historyApiFallback.index loses its leading / which breaks the dev-server SPA fallback
platform/app/.webpack/writePluginImportsFile.js Generates pluginImports.js with a getRuntimeImportPath helper that routes non-HTTP import paths through getPublicSubPath, correctly handling subpath deployments
platform/app/public/manifest.json Icon paths changed to relative (assets/… without leading /), allowing the manifest to resolve correctly under any subpath
platform/core/src/utils/index.ts Exports the five new publicUrl utilities through the package surface; straightforward additions
platform/core/src/index.ts Re-exports the new utilities at the top-level @ohif/core package boundary; straightforward additions
platform/app/src/index.js Adds import './setRuntimePublicPath' as the first import, ensuring __webpack_public_path__ is set before any dynamic chunk loading occurs
Prompt To Fix All With AI
This is a comment left during a code review.
Path: platform/app/src/utils/publicUrl.ts
Line: 1

Comment:
**Direct import from raw TypeScript source**

This file imports from `'../../../core/src/utils/publicUrl'` (the raw `.ts` source) instead of the published `@ohif/core` package — the same pattern that was flagged and already fixed in `setRuntimePublicPath.js`. While it works in a monorepo build, it bypasses the package boundary and will break if `@ohif/core` ever ships pre-compiled or if the internal path is reorganized.

```suggestion
import { normalizePublicUrl, toRouterBasename } from '@ohif/core';
```

How can I resolve this? If you propose a fix, please make it concise.

---

This is a comment left during a code review.
Path: platform/app/.webpack/webpack.pwa.js
Line: 176

Comment:
**`historyApiFallback.index` missing leading slash**

The old value was `PUBLIC_URL + 'index.html'` which defaulted to `'/index.html'`. The replacement drops the leading `/`. The `connect-history-api-fallback` middleware (used internally by webpack-dev-server) expects a root-relative path beginning with `/`; without it the SPA fallback won't serve `index.html` for unmatched routes during local development.

```suggestion
        index: '/index.html',
```

How can I resolve this? If you propose a fix, please make it concise.

Reviews (2): Last reviewed commit: "fix(app): derive base path from last vie..." | Re-trigger Greptile

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 20, 2026

Deploy Preview for ohif-dev ready!

Name Link
🔨 Latest commit 7d9400f
🔍 Latest deploy log https://app.netlify.com/projects/ohif-dev/deploys/69e5d01f3ba1030008f008b9
😎 Deploy Preview https://deploy-preview-5969--ohif-dev.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@nutzlastfan nutzlastfan marked this pull request as ready for review April 20, 2026 06:41
Comment thread platform/core/src/utils/publicUrl.ts Outdated
Comment thread platform/app/src/setRuntimePublicPath.js Outdated
Comment thread platform/app/public/html-templates/index.html
Comment thread platform/core/src/utils/publicUrl.ts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant