Skip to content
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

fix(vue-app): serialize route meta to contain functions #9634

Merged
merged 1 commit into from Aug 11, 2021

Conversation

SlayerOfTheBad
Copy link

@SlayerOfTheBad SlayerOfTheBad commented Aug 5, 2021

Types of changes

  • Bug fix (a non-breaking change which fixes an issue)
  • New feature (a non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Description

This pull request serializes route.meta in recursiveRoutes in router.js

JSON.stringify is lossy, especially with regards to functions. vue-router meta should be able to support functions for things such as having a dynamic route name. Using JSON.stringyfy removes all of these functions, whereas serialize() preserves them. I assumed it to be safe to use, as it is also used for route.redirect and route.props in the same file.

This problem is shown in (this)[https://codesandbox.io/s/kind-glitter-ui9lm?file=/pages/page.vue] code sandbox, by going to the /page route, and clicking the button, the router meta is printed to the console.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly. (PR: #)
  • I have added tests to cover my changes (if not applicable, please state why)
  • All new and existing tests are passing.

I have not added a test as I could not find a test file for the relevant functionality, and it seemed too integrated for me to be comfortable writing my own test for it.

Locally packagers/cli/test/unit/command.test.js is failing on cli/command > returns Builder instance, but was already failing before I made any edits.

@pi0 pi0 changed the title fix(recursiveRoutes): Enable route meta to contain functions fix(vue-app): serialize route meta to contain functions Aug 11, 2021
@pi0
Copy link
Member

pi0 commented Aug 11, 2021

Thanks for PR @SlayerOfTheBad. While it makes sense as we already allow serialization from nuxt.config, I highly recommend against doing this and finding a strategy to use a nuxt plugin to do it. There are many edge cases with serializing (like we cannot use an external variable and language level is not same)

@pi0 pi0 merged commit 457984a into nuxt:dev Aug 11, 2021
@pi0 pi0 mentioned this pull request Aug 11, 2021
@danielroe danielroe added the 2.x label Jan 18, 2023
@danielroe danielroe mentioned this pull request Jan 19, 2023
@danielroe danielroe mentioned this pull request Feb 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants