mirror of
https://github.com/pterodactyl/panel.git
synced 2026-12-01 20:05:48 -05:00
## Problem
An extension built with the SDK Vite preset whose lazy screens share a
module requests its shared chunk from the site root. For example
`/chunk.api.Hb1egxRz.js` returns the single page app shell (status 200,
`text/html`), and the browser logs `Failed to load module script:
Expected a JavaScript module script but the server responded with a MIME
type of "text/html"`. The extension still works, because the real
imports are relative, but every page load that touches such a screen
produces failing requests and console errors.
## Reproduction
1. Scaffold an extension with `php artisan p:extension:make demo`.
2. Register two screens with `screens.register('a', () =>
import('./A'))` and `screens.register('b', () => import('./B'))`, where
both import the same helper module.
3. Build it and enable it, then open one of the screens with the browser
network panel open.
The built `dist/client.js` starts with a `__vite__mapDeps` list of bare
chunk file names. Vite's preload helper resolves those names against the
document, not against the bundle.
## Root cause
Vite emits a `modulepreload` dependency map for dynamic imports. The
preset does not turn it off, and the helper's base is the page URL, so
the extension's chunk names resolve to the site root.
## Fix
Set `build.modulePreload` to `false` in `defineExtensionConfig`. Chunks
import each other with relative URLs, which already resolve against the
bundle, so nothing else changes. Preloading is only a hint.
## Testing
* New test in `packages/sdk/vite.spec.ts` builds an entry with two lazy
imports that share a module and asserts that the output contains no
preload map. It fails before the change and passes after it.
* `npx vitest run packages/sdk/vite.spec.ts` passes.
* Checked in a browser: the failing requests for the shared chunk
disappear and the screens still load.
## Compatibility considerations
Extensions rebuilt with the new preset lose a performance hint only.
Existing builds keep working as before.