mirror of
https://github.com/withastro/astro.git
synced 2024-12-16 21:46:22 -05:00
Fix markdoc test fail in main (#7459)
* Early out if `importedModule` has no `id` We can do this as line 97 also has this guard for each `importedModules` * Simplify `isPropagationStoppingPoint` * Fix actual bug * chore: changeset --------- Co-authored-by: bholmesdev <hey@bholmes.dev>
This commit is contained in:
parent
dfa70357d3
commit
869197aafd
3 changed files with 46 additions and 45 deletions
5
.changeset/cool-birds-prove.md
Normal file
5
.changeset/cool-birds-prove.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'astro': patch
|
||||
---
|
||||
|
||||
Fix missing styles for Markdoc files in development
|
|
@ -46,13 +46,12 @@ export async function* crawlGraph(
|
|||
const entryIsStyle = isCSSRequest(id);
|
||||
|
||||
for (const importedModule of entry.importedModules) {
|
||||
// A propagation stopping point is a module with the ?astroPropagatedAssets flag.
|
||||
// When we encounter one of these modules we don't want to continue traversing.
|
||||
let isPropagationStoppingPoint = false;
|
||||
if (!importedModule.id) continue;
|
||||
|
||||
// some dynamically imported modules are *not* server rendered in time
|
||||
// to only SSR modules that we can safely transform, we check against
|
||||
// a list of file extensions based on our built-in vite plugins
|
||||
if (importedModule.id) {
|
||||
|
||||
// Strip special query params like "?content".
|
||||
// NOTE: Cannot use `new URL()` here because not all IDs will be valid paths.
|
||||
// For example, `virtual:image-loader` if you don't have the plugin installed.
|
||||
|
@ -64,10 +63,11 @@ export async function* crawlGraph(
|
|||
if (entryIsStyle && !isCSSRequest(importedModulePathname)) {
|
||||
continue;
|
||||
}
|
||||
const isFileTypeNeedingSSR = fileExtensionsToSSR.has(
|
||||
npath.extname(importedModulePathname)
|
||||
);
|
||||
isPropagationStoppingPoint = ASTRO_PROPAGATED_ASSET_REGEX.test(importedModule.id);
|
||||
|
||||
const isFileTypeNeedingSSR = fileExtensionsToSSR.has(npath.extname(importedModulePathname));
|
||||
// A propagation stopping point is a module with the ?astroPropagatedAssets flag.
|
||||
// When we encounter one of these modules we don't want to continue traversing.
|
||||
const isPropagationStoppingPoint = ASTRO_PROPAGATED_ASSET_REGEX.test(importedModule.id);
|
||||
if (
|
||||
isFileTypeNeedingSSR &&
|
||||
// Should not SSR a module with ?astroPropagatedAssets
|
||||
|
@ -82,8 +82,9 @@ export async function* crawlGraph(
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (urlDeps.includes(urlId(importedModule.url)) && !isPropagationStoppingPoint) {
|
||||
|
||||
// Make sure the `importedModule` traversed is explicitly imported by the user, and not by HMR
|
||||
if (urlDeps.includes(importedModule.url) && !isPropagationStoppingPoint) {
|
||||
importedModules.add(importedModule);
|
||||
}
|
||||
}
|
||||
|
@ -102,18 +103,10 @@ export async function* crawlGraph(
|
|||
}
|
||||
}
|
||||
|
||||
// Virtual modules URL should start with /@id/ but do not
|
||||
function urlId(url: string) {
|
||||
if (url.startsWith('astro:scripts')) {
|
||||
return '/@id/' + url;
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
function getDepsFromEntry(entry: ModuleNode) {
|
||||
let deps = entry.ssrTransformResult?.deps ?? [];
|
||||
if (entry.ssrTransformResult?.dynamicDeps) {
|
||||
return deps.concat(entry.ssrTransformResult.dynamicDeps);
|
||||
deps = deps.concat(entry.ssrTransformResult.dynamicDeps);
|
||||
}
|
||||
return deps;
|
||||
return deps.map((dep) => unwrapId(dep));
|
||||
}
|
||||
|
|
|
@ -93,11 +93,14 @@ export function viteID(filePath: URL): string {
|
|||
}
|
||||
|
||||
export const VALID_ID_PREFIX = `/@id/`;
|
||||
export const NULL_BYTE_PLACEHOLDER = `__x00__`;
|
||||
|
||||
// Strip valid id prefix. This is prepended to resolved Ids that are
|
||||
// not valid browser import specifiers by the importAnalysis plugin.
|
||||
// Strip valid id prefix and replace null byte placeholder. Both are prepended to resolved ids
|
||||
// as they are not valid browser import specifiers (by the Vite's importAnalysis plugin)
|
||||
export function unwrapId(id: string): string {
|
||||
return id.startsWith(VALID_ID_PREFIX) ? id.slice(VALID_ID_PREFIX.length) : id;
|
||||
return id.startsWith(VALID_ID_PREFIX)
|
||||
? id.slice(VALID_ID_PREFIX.length).replace(NULL_BYTE_PLACEHOLDER, '\0')
|
||||
: id;
|
||||
}
|
||||
|
||||
export function resolvePages(config: AstroConfig) {
|
||||
|
|
Loading…
Reference in a new issue