Skip to content

Conversation

@mohab-sameh
Copy link
Contributor

Closes #70

Fix: Only Add Key to useAsyncData if useRoute Variable is Present

Overview

This PR fixes a bug in the nuxt/4/shallow-function-reactivity codemod where it would incorrectly prepend .params.slug as a key to useAsyncData even when no variable was assigned to useRoute(). This resulted in invalid code being generated in some cases.

What Was Changed

  • Codemod logic updated:
    The codemod now only adds a key (e.g., route.params.slug) to useAsyncData if a variable assigned to useRoute() is found in the file. If not, it skips this transformation, preventing invalid code like .params.slug.
  • Test coverage improved:
    Added test cases for both scenarios:
    • When a useRoute() variable is present (should add the key)
    • When no useRoute() variable is present (should not add a key)
  • Documentation:
    Updated documentation and changelog to reflect the fix and new tests.

Why

Previously, the codemod would always attempt to add .params.slug as a key, even if there was no variable assigned to useRoute(), resulting in broken code. This fix ensures the codemod only applies the transformation when it is safe and correct to do so.

How to Test

  • Run the codemod on code with and without a useRoute() variable in scope for useAsyncData.
  • Verify that the transformation only occurs when appropriate. Confirm that no regressions have been introduced.
  • See the new test fixtures for examples.

… if useRoute variable is found; add tests and docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[codemod][FP/FN] nuxt/4/migration-recipe

2 participants