mirror of
https://github.com/withastro/astro.git
synced 2024-12-30 22:03:56 -05:00
Fix prefetch sourcemap generation (#12346)
This commit is contained in:
parent
836cd91c37
commit
20e5a843c8
2 changed files with 21 additions and 6 deletions
5
.changeset/heavy-walls-rhyme.md
Normal file
5
.changeset/heavy-walls-rhyme.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Fixes sourcemap generation when prefetch is enabled
|
|
@ -45,15 +45,25 @@ export default function astroPrefetch({ settings }: { settings: AstroSettings })
|
||||||
},
|
},
|
||||||
transform(code, id) {
|
transform(code, id) {
|
||||||
// NOTE: Handle replacing the specifiers even if prefetch is disabled so View Transitions
|
// NOTE: Handle replacing the specifiers even if prefetch is disabled so View Transitions
|
||||||
// can import the internal module as not hit runtime issues.
|
// can import the internal module and not hit runtime issues.
|
||||||
if (id.includes(prefetchInternalModuleFsSubpath)) {
|
if (id.includes(prefetchInternalModuleFsSubpath)) {
|
||||||
return code
|
// We perform a simple replacement with padding so that the code offset is not changed and
|
||||||
.replace('__PREFETCH_PREFETCH_ALL__', JSON.stringify(prefetch?.prefetchAll))
|
// we don't have to generate a sourcemap. This has the assumption that the replaced string
|
||||||
.replace('__PREFETCH_DEFAULT_STRATEGY__', JSON.stringify(prefetch?.defaultStrategy))
|
// will always be shorter than the search string to work.
|
||||||
|
code = code
|
||||||
.replace(
|
.replace(
|
||||||
'__EXPERIMENTAL_CLIENT_PRERENDER__',
|
'__PREFETCH_PREFETCH_ALL__', // length: 25
|
||||||
JSON.stringify(settings.config.experimental.clientPrerender),
|
`${JSON.stringify(prefetch?.prefetchAll)}`.padEnd(25),
|
||||||
|
)
|
||||||
|
.replace(
|
||||||
|
'__PREFETCH_DEFAULT_STRATEGY__', // length: 29
|
||||||
|
`${JSON.stringify(prefetch?.defaultStrategy)}`.padEnd(29),
|
||||||
|
)
|
||||||
|
.replace(
|
||||||
|
'__EXPERIMENTAL_CLIENT_PRERENDER__', // length: 33
|
||||||
|
`${JSON.stringify(settings.config.experimental.clientPrerender)}`.padEnd(33),
|
||||||
);
|
);
|
||||||
|
return { code, map: null };
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue