Skip to content

Fix syntax error handling in definePage to prevent Vite crashes #693

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

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Aug 11, 2025

When invalid syntax is used in definePage() calls, the Vite dev server would crash instead of gracefully handling the error. This happened because parsing errors from Babel were not caught and would bubble up, terminating the development server.

For example, this invalid syntax would crash the server:

<script setup lang="ts">
definePage({ 2, 3 }) // syntax error by accident
</script>

Changes made:

  • Added comprehensive error handling in getCodeAst() function to catch parsing errors from babelParse() and Vue SFC parsing methods
  • When syntax errors occur:
    • Normal transform returns undefined to skip processing
    • DefinePage extraction returns 'export default {}' as a safe fallback
    • Logs a warning message instead of crashing
  • Both definePageTransform() and extractDefinePageNameAndPath() now handle errors gracefully
  • Added comprehensive test coverage for various syntax error scenarios

The fix ensures that developers can continue working even when they accidentally introduce syntax errors in definePage() calls, while preserving all existing functionality for valid code.

Fixes #691.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@Copilot Copilot AI assigned Copilot and posva Aug 11, 2025
Copy link
Author

Copilot AI commented Aug 11, 2025

@posva 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copy link

cloudflare-workers-and-pages bot commented Aug 11, 2025

Deploying unplugin-vue-router with  Cloudflare Pages  Cloudflare Pages

Latest commit: cdb584f
Status: ✅  Deploy successful!
Preview URL: https://520bfd4d.unplugin-vue-router.pages.dev
Branch Preview URL: https://copilot-fix-691.unplugin-vue-router.pages.dev

View logs

Copy link

codecov bot commented Aug 11, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@4e5015e). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #693   +/-   ##
=======================================
  Coverage        ?   60.90%           
=======================================
  Files           ?       36           
  Lines           ?     3379           
  Branches        ?      618           
=======================================
  Hits            ?     2058           
  Misses          ?     1314           
  Partials        ?        7           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI and others added 2 commits August 11, 2025 09:27
Co-authored-by: posva <664177+posva@users.noreply.github.com>
Co-authored-by: posva <664177+posva@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] definePage a error object will make vite crash Fix syntax error handling in definePage to prevent Vite crashes Aug 11, 2025
@Copilot Copilot AI requested a review from posva August 11, 2025 09:35
Copilot finished work on behalf of posva August 11, 2025 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

definePage a error object will make vite crash
2 participants