Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(preset-umi): disable route preload feature if unnecessary #12186

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -206,14 +206,21 @@ async function getRoutePathFilesMap(
export default (api: IApi) => {
let routeChunkFilesMap: IRouteChunkFilesMap;

// enable when package name available
// because preload script use package name as attribute prefix value
api.describe({
enableBy: () => Boolean(api.pkg.name),
enableBy: () =>
// enable when package name available
// because preload script use package name as attribute prefix value
Boolean(api.pkg.name) &&
// vite mode is not supported currently
!api.config.vite &&
// mpa mode is unnecessary
!api.config.mpa &&
// only esm router needs this feature
api.config.routeLoader?.moduleType === 'esm',
});

api.addHTMLHeadScripts(() => {
if (api.name === 'build') {
if (api.name === 'build' && routeChunkFilesMap) {
// internal tern app use map mode
return api.config.tern
? // map mode
Expand Down Expand Up @@ -278,22 +285,24 @@ export default (api: IApi) => {
);

// 3. generate final route chunk files map
routeChunkFilesMap = {
p: api.pkg.name!,
b: api.appData.bundler!,
f: Object.entries(routeChunkFiles)
.sort((a, b) => a[1].index - b[1].index)
.map(([k, { id }]) => [k, id]),
// sort similar to react-router@6
r: lodash(routeFilesMap)
.toPairs()
.sort(
([a]: [string, number[]], [b]: [string, number[]]) =>
computeRouteScore(a) - computeRouteScore(b),
)
.fromPairs()
.value() as any,
};
if (!lodash.isEmpty(routeChunkFiles) && !lodash.isEmpty(routeFilesMap)) {
routeChunkFilesMap = {
p: api.pkg.name!,
b: api.appData.bundler!,
f: Object.entries(routeChunkFiles)
.sort((a, b) => a[1].index - b[1].index)
.map(([k, { id }]) => [k, id]),
// sort similar to react-router@6
r: lodash(routeFilesMap)
.toPairs()
.sort(
([a]: [string, number[]], [b]: [string, number[]]) =>
computeRouteScore(a) - computeRouteScore(b),
)
.fromPairs()
.value() as any,
};
}
}
});
};
Loading