Commit fef54db
authored
fix: skip MDX files during RSC scan-build to prevent parse errors (#668)
* fix: skip MDX files during RSC scan-build to prevent parse errors (issue #659)
Adds a vinext:rsc-scan-mdx-guard plugin that runs with enforce:"pre"
to ensure MDX files are skipped before rsc:scan-strip processes them.
This prevents es-module-lexer parse errors when MDX files contain
frontmatter (---) or JSX that isn't valid JavaScript syntax.
Also adds a regression test that uses MDX files with YAML frontmatter
loaded via import.meta.glob to verify the build succeeds.
* fix(mdx): return stub module for undetected MDX files during scan-build
The guard plugin was a no-op that passed raw MDX through unchanged. When
rsc:scan-strip received this raw MDX, es-module-lexer.parse() failed on
frontmatter (---) and JSX syntax.
The real fix is in vinext:mdx: when mdxDelegate is null (no MDX files in app/
or pages/), return a valid JS stub module instead of undefined. This handles
MDX files that enter the build graph via import.meta.glob outside app/pages.
- Remove vinext:rsc-scan-mdx-guard plugin (was a no-op)
- Modify vinext:mdx to return stub module when mdxDelegate is null
- Remove app/mdx-probe/page.mdx from test (was hiding the bug)
- Replace fragile '---' assertion with specific frontmatter checks
Fixes issue #659
* fix(mdx): lazily compile globbed mdx imports
Compile plain .mdx files on demand when they enter the graph via import.meta.glob outside app/pages so scan-build stops crashing without discarding runtime content. Restore the existing happy-path MDX fixture, add focused lazy-compilation coverage, and extract shared Cloudflare fixture setup to keep the regression tests honest.
* fix review issues
* fix: use absolute path for root tsconfig alias to fix import.meta.glob resolution
toViteAliasReplacement was returning "/" (Vite root-relative convention) when
the tsconfig path alias pointed to the project root (e.g. "@/*": ["./*"]).
This worked for regular imports but broke import.meta.glob because Vite's
glob plugin resolves patterns via this.resolve(), which couldn't properly
resolve the "/" replacement to matching filesystem files.
Changed to return the absolute path instead, which works correctly for both
regular imports and glob pattern resolution.
Signed-off-by: Divanshu Chauhan <divkix@divkix.me>
Made-with: Cursor
* refactor: address review feedback on MDX lazy initialization
- Add clarifying comments for mdxDelegatePromise caching semantics
- Document subtle control flow when hasUserMdxPlugin is true
- Suppress duplicate warning on on-demand MDX init (only warn during detection)
- Add case-insensitive extension check in transform hook
- Add test for query parameter edge cases (?raw, ?v=123, etc.)
* refactor: address review feedback on MDX handling
- Merge duplicate query-param MDX skip tests in pages-router.test.ts
- Tighten hasUserMdxPlugin control flow comment for clarity
- Make scanDirForMdx case-insensitive to align with transform check
Refs: PR #668 review feedback
* docs: clarify mdx delegate fallback comment
* chore: trigger ci
---------
Signed-off-by: Divanshu Chauhan <divkix@divkix.me>1 parent f8a28fd commit fef54db
4 files changed
Lines changed: 309 additions & 134 deletions
File tree
- packages/vinext/src
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
203 | 203 | | |
204 | 204 | | |
205 | 205 | | |
206 | | - | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
207 | 209 | | |
208 | 210 | | |
209 | 211 | | |
| |||
1039 | 1041 | | |
1040 | 1042 | | |
1041 | 1043 | | |
1042 | | - | |
1043 | | - | |
| 1044 | + | |
| 1045 | + | |
| 1046 | + | |
1044 | 1047 | | |
| 1048 | + | |
| 1049 | + | |
| 1050 | + | |
| 1051 | + | |
| 1052 | + | |
| 1053 | + | |
| 1054 | + | |
| 1055 | + | |
| 1056 | + | |
| 1057 | + | |
| 1058 | + | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
| 1070 | + | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
| 1077 | + | |
| 1078 | + | |
| 1079 | + | |
| 1080 | + | |
| 1081 | + | |
| 1082 | + | |
| 1083 | + | |
| 1084 | + | |
| 1085 | + | |
| 1086 | + | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
| 1097 | + | |
| 1098 | + | |
| 1099 | + | |
| 1100 | + | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
| 1106 | + | |
1045 | 1107 | | |
1046 | 1108 | | |
1047 | 1109 | | |
| |||
1348 | 1410 | | |
1349 | 1411 | | |
1350 | 1412 | | |
1351 | | - | |
| 1413 | + | |
1352 | 1414 | | |
1353 | 1415 | | |
1354 | 1416 | | |
1355 | 1417 | | |
1356 | 1418 | | |
1357 | 1419 | | |
1358 | 1420 | | |
1359 | | - | |
| 1421 | + | |
1360 | 1422 | | |
1361 | 1423 | | |
1362 | | - | |
1363 | | - | |
1364 | | - | |
1365 | | - | |
1366 | | - | |
1367 | | - | |
1368 | | - | |
1369 | | - | |
1370 | | - | |
1371 | | - | |
1372 | | - | |
1373 | | - | |
1374 | | - | |
1375 | | - | |
1376 | | - | |
1377 | | - | |
1378 | | - | |
1379 | | - | |
1380 | | - | |
1381 | | - | |
1382 | | - | |
1383 | | - | |
1384 | | - | |
1385 | | - | |
1386 | | - | |
1387 | | - | |
1388 | | - | |
1389 | | - | |
| 1424 | + | |
1390 | 1425 | | |
1391 | 1426 | | |
1392 | 1427 | | |
| |||
1972 | 2007 | | |
1973 | 2008 | | |
1974 | 2009 | | |
1975 | | - | |
| 2010 | + | |
1976 | 2011 | | |
1977 | 2012 | | |
1978 | 2013 | | |
1979 | | - | |
1980 | | - | |
1981 | | - | |
1982 | | - | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
| 2019 | + | |
| 2020 | + | |
| 2021 | + | |
| 2022 | + | |
| 2023 | + | |
| 2024 | + | |
| 2025 | + | |
| 2026 | + | |
| 2027 | + | |
| 2028 | + | |
| 2029 | + | |
| 2030 | + | |
1983 | 2031 | | |
1984 | 2032 | | |
1985 | 2033 | | |
| |||
3870 | 3918 | | |
3871 | 3919 | | |
3872 | 3920 | | |
3873 | | - | |
| 3921 | + | |
3874 | 3922 | | |
3875 | 3923 | | |
3876 | 3924 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1474 | 1474 | | |
1475 | 1475 | | |
1476 | 1476 | | |
1477 | | - | |
| 1477 | + | |
1478 | 1478 | | |
1479 | 1479 | | |
1480 | 1480 | | |
| |||
1484 | 1484 | | |
1485 | 1485 | | |
1486 | 1486 | | |
1487 | | - | |
| 1487 | + | |
1488 | 1488 | | |
1489 | 1489 | | |
1490 | | - | |
| 1490 | + | |
1491 | 1491 | | |
1492 | 1492 | | |
1493 | 1493 | | |
1494 | 1494 | | |
1495 | 1495 | | |
1496 | 1496 | | |
1497 | 1497 | | |
1498 | | - | |
1499 | | - | |
1500 | | - | |
| 1498 | + | |
| 1499 | + | |
| 1500 | + | |
| 1501 | + | |
| 1502 | + | |
| 1503 | + | |
| 1504 | + | |
| 1505 | + | |
| 1506 | + | |
| 1507 | + | |
| 1508 | + | |
| 1509 | + | |
| 1510 | + | |
| 1511 | + | |
| 1512 | + | |
| 1513 | + | |
| 1514 | + | |
| 1515 | + | |
| 1516 | + | |
| 1517 | + | |
| 1518 | + | |
| 1519 | + | |
| 1520 | + | |
| 1521 | + | |
| 1522 | + | |
| 1523 | + | |
| 1524 | + | |
| 1525 | + | |
| 1526 | + | |
| 1527 | + | |
| 1528 | + | |
| 1529 | + | |
| 1530 | + | |
| 1531 | + | |
| 1532 | + | |
| 1533 | + | |
| 1534 | + | |
| 1535 | + | |
| 1536 | + | |
| 1537 | + | |
| 1538 | + | |
| 1539 | + | |
| 1540 | + | |
| 1541 | + | |
| 1542 | + | |
| 1543 | + | |
| 1544 | + | |
| 1545 | + | |
| 1546 | + | |
| 1547 | + | |
| 1548 | + | |
| 1549 | + | |
| 1550 | + | |
1501 | 1551 | | |
1502 | 1552 | | |
1503 | 1553 | | |
| |||
0 commit comments