fix(nuxt/4/shallow-function-reactivity): only add key to useAsyncData… #71
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #70
Fix: Only Add Key to
useAsyncDataifuseRouteVariable is PresentOverview
This PR fixes a bug in the
nuxt/4/shallow-function-reactivitycodemod where it would incorrectly prepend.params.slugas a key touseAsyncDataeven when no variable was assigned touseRoute(). This resulted in invalid code being generated in some cases.What Was Changed
The codemod now only adds a key (e.g.,
route.params.slug) touseAsyncDataif a variable assigned touseRoute()is found in the file. If not, it skips this transformation, preventing invalid code like.params.slug.Added test cases for both scenarios:
useRoute()variable is present (should add the key)useRoute()variable is present (should not add a key)Updated documentation and changelog to reflect the fix and new tests.
Why
Previously, the codemod would always attempt to add
.params.slugas a key, even if there was no variable assigned touseRoute(), 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
useRoute()variable in scope foruseAsyncData.