Skip to content

[stable32] fix(template): add import map for JS module entry points#60659

Open
backportbot[bot] wants to merge 1 commit into
stable32from
backport/56941/stable32
Open

[stable32] fix(template): add import map for JS module entry points#60659
backportbot[bot] wants to merge 1 commit into
stable32from
backport/56941/stable32

Conversation

@backportbot
Copy link
Copy Markdown

@backportbot backportbot Bot commented May 22, 2026

Backport of PR #56941

Currently apps are broken if they have exports in the JS entry point,
because they then will import from the entry point but because they do
not know about the Nextcloud cache buster they will import without cache
buster.

This results in two problem:
1. The module might be outdated (old cached)
2. The module is duplicated, so the module will be loaded twice and will
   have two different - out of sync - states. This also means it will
   re-run sideeffects of the entry point.

To fix this we generate an import map which basically maps the plain
entry point script to the script with cache buster added.

(Some background: Bundler will try to minimize chunks (reduce page
loading time) so they can inline modules into entry points and thus
extend the entry point exports and then this issue would be caused).

For example:
```js
// entry.mjs
console.error('called')

async function onClick() {
  await import('./chunk.mjs')
}

export const name = 'foo'

// chunk.mjs
import { name } from './entry.mjs'

console.error(name)
```

When calling `onClick` without this fix the output will be:
> called
> called
> foo

With this fix:
> called
> foo

Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de>
@backportbot backportbot Bot requested a review from a team as a code owner May 22, 2026 14:06
@backportbot backportbot Bot requested review from Altahrim, ArtificialOwl, ShGKme, artonge, come-nc, leftybournes and susnux and removed request for a team May 22, 2026 14:06
@backportbot backportbot Bot added this to the Nextcloud 32.0.10 milestone May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants