fix: add trailing slash to hardcoded kubeflow BASE_PATH in webpack config - #1349
Conversation
…nfig In config/webpack.common.js and config/webpack.dev.js, BASE_PATH for DEPLOYMENT_MODE=kubeflow was hardcoded to '/workspaces' without a trailing slash. This value is baked into the production build as webpack's runtime publicPath (__webpack_require__.p), and webpack's dynamic-chunk-loading runtime concatenates that value directly with the chunk filename without inserting a separator. As a result, any lazily-loaded route chunk was requested as e.g. "/workspaces449.bundle.js" instead of "/workspaces/449.bundle.js" in production, which the Istio VirtualService for this frontend (prefix: /workspaces/) never matches, causing a ChunkLoadError in the browser when e.g. opening the Workspace details view. The entry bundle itself was unaffected because html-webpack-plugin normalizes publicPath when injecting <script>/<base> tags into index.html, masking the bug for anything not code-split. Assisted-by: Claude Sonnet 5 <noreply@anthropic.com> Signed-off-by: Christian Heusel <christian@heusel.eu>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
thisis-Shitanshu
left a comment
There was a problem hiding this comment.
Tested this against a local KIND Kubeflow Community Distribution deployment.
I was able to reproduce the issue before the change: opening the Workspace details view requested lazy chunks such as /workspaces6990.bundle.js, which returned HTML in my environment and resulted in Unexpected token '<' followed by a ChunkLoadError.
I then built and deployed this PR and repeated the same flow with cache disabled. The chunk is now requested correctly as /workspaces/6990.bundle.js, returns application/javascript with 200, and the ChunkLoadError is gone.
The trailing slash change looks correct to me. LGTM 👍
|
@thisis-Shitanshu: changing LGTM is restricted to collaborators DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
Summary
In production/Kubeflow-mode builds of
workspaces/frontend, opening a route that requires a lazily-loaded webpack chunk (e.g. the Workspace details view) fails with aChunkLoadError. The browser requests a malformed URL like/workspaces449.bundle.jsinstead of/workspaces/449.bundle.js, which doesn't match this frontend's IstioVirtualServiceprefix match (prefix: /workspaces/) and therefore never reaches the app's own nginx.Root cause:
config/webpack.common.jsandconfig/webpack.dev.jshardcodeBASE_PATHto the literal'/workspaces'(no trailing slash) wheneverDEPLOYMENT_MODE === 'kubeflow':This value becomes webpack's runtime
publicPath(__webpack_require__.p), which webpack's dynamicimport()runtime uses via raw string concatenation with the chunk filename — it does not insert a/separator, sincepublicPathis expected to already end in one. So a chunk file449.bundle.jsgets requested as'/workspaces' + '449.bundle.js'=/workspaces449.bundle.js.The entry bundle (
app.bundle.js) is unaffected becausehtml-webpack-pluginnormalizespublicPathitself when injecting the<script>tag and<base href>intoindex.html— only dynamically imported chunks go through the raw webpack runtime and hit the bug. This is also why it's easy to miss in local dev:.env.tiltsetsDEPLOYMENT_MODE=standaloneandPUBLIC_PATH=/workspaces/(with a trailing slash already), which takes the other branch of the ternary and never triggers the bug.Fix
Add the missing trailing slash to the hardcoded
kubeflow-mode literal in both files, matching whatPUBLIC_PATH=/workspaces/already does correctly for the non-kubeflowbranch:Verification
npm run build:prodand confirmed the builtapp.bundle.jsnow embeds__webpack_require__.p="/workspaces/"(previously"/workspaces"), so lazily-loaded chunks now resolve to/workspaces/<id>.bundle.js.dist/index.html's<base href>and<script src>are unaffected (still correctly/workspaces/...) — only the runtime chunk-loading path was wrong before this change.npm run test:lintpasses.ChunkLoadError: Loading chunk 449 failed. (missing: http://<host>/workspaces449.bundle.js)in the browser console, with the network request returning a non-2xx response since it doesn't match this service's Istio route.Test plan
npm run build:prodsucceeds and the emittedapp.bundle.jshaspublicPath=/workspaces/npm run test:lintpassesChunkLoadErrorand the details panel renders (reviewer/CI verification)