Skip to content

fix(nuxt): use klona to deep clone extractedMeta #30717

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

Merged
merged 5 commits into from
Jan 24, 2025
Merged

Conversation

xjccc
Copy link
Contributor

@xjccc xjccc commented Jan 23, 2025

🔗 Linked issue

resolves #30695

📚 Description

I think add a unique cacheKey with hash(route) could resolve this?

If has any other idea, please tell me. Thank you very much.

@xjccc xjccc requested a review from danielroe as a code owner January 23, 2025 04:33
Copy link

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link

coderabbitai bot commented Jan 23, 2025

Walkthrough

The pull request introduces changes to the getRouteMeta function in the Nuxt package, focusing on metadata handling and cloning. The modifications involve using the klona function to create deep clones of cached and extracted metadata. This approach ensures that the original metadata objects remain unaltered when accessed, preventing potential side effects from direct modifications.

The changes impact three primary files: packages/nuxt/src/pages/utils.ts, packages/nuxt/test/page-metadata.test.ts, and packages/nuxt/test/pages.test.ts. In the utils file, the function now returns deep-cloned metadata, and its method signature has been updated for more precise type information. The test file for getRouteMeta adjusts its assertions to verify the cache invalidation mechanism, while a new test suite is added to check the handling of route metadata for multiple entries referencing the same file but with different metadata.

These modifications enhance the robustness of metadata handling in the Nuxt page routing system by implementing safer object cloning techniques and expanding test coverage.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8b93550 and 29adcd0.

📒 Files selected for processing (1)
  • packages/nuxt/test/page-metadata.test.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/nuxt/test/page-metadata.test.ts
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: test-fixtures (windows-latest, built, rspack, default, manifest-on, json, 18)
  • GitHub Check: test-fixtures (windows-latest, built, rspack, async, manifest-on, json, 18)
  • GitHub Check: test-fixtures (windows-latest, built, vite, default, manifest-on, json, 18)
  • GitHub Check: test-fixtures (windows-latest, built, vite, async, manifest-off, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, webpack, default, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, webpack, async, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, rspack, default, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, rspack, async, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-off, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-off, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, js, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-off, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-off, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, js, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, json, 18)
  • GitHub Check: test-benchmark
  • GitHub Check: release-pr

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

pkg-pr-new bot commented Jan 23, 2025

Open in Stackblitz

@nuxt/kit

npm i https://pkg.pr.new/@nuxt/kit@30717

@nuxt/rspack-builder

npm i https://pkg.pr.new/@nuxt/rspack-builder@30717

nuxt

npm i https://pkg.pr.new/nuxt@30717

@nuxt/schema

npm i https://pkg.pr.new/@nuxt/schema@30717

@nuxt/vite-builder

npm i https://pkg.pr.new/@nuxt/vite-builder@30717

@nuxt/webpack-builder

npm i https://pkg.pr.new/@nuxt/webpack-builder@30717

commit: 29adcd0

Copy link

codspeed-hq bot commented Jan 23, 2025

CodSpeed Performance Report

Merging #30717 will not alter performance

Comparing xjccc:fix/30695 (29adcd0) with main (af52b47)

Summary

✅ 8 untouched benchmarks

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/nuxt/test/pages.test.ts (2)

841-854: Consider enhancing test coverage and clarity.

While the test effectively verifies the basic functionality, consider these improvements:

  1. Use more realistic path names (e.g., '/about', '/about-team', '/about-company')
  2. Use more descriptive metadata properties that reflect real use cases
  3. Add test cases for error scenarios (e.g., conflicting metadata)
 const files: NuxtPage[] = [
-  { path: 'home', file: `pages/index.vue` },
-  { path: 'home1', file: `pages/index.vue`, meta: { test: true } },
-  { path: 'home2', file: `pages/index.vue`, meta: { snap: true } },
+  { path: 'about', file: `pages/index.vue` },
+  { path: 'about-team', file: `pages/index.vue`, meta: { layout: 'team' } },
+  { path: 'about-company', file: `pages/index.vue`, meta: { layout: 'company' } },
 ]

856-872: Enhance assertion specificity.

Consider adding more specific assertions to verify:

  1. The shared file content (definePageMeta) is correctly applied to all routes
  2. The metadata isolation between routes is maintained
 await augmentPages(files, vfs)
+// Verify shared content is applied
+for (const file of files) {
+  expect(file.meta).toHaveProperty(DYNAMIC_META_KEY)
+  expect(file.meta[DYNAMIC_META_KEY]).toBeInstanceOf(Set)
+  expect(file.meta[DYNAMIC_META_KEY].has('meta')).toBe(true)
+}
+
+// Verify metadata isolation
+expect(files[1].meta).not.toEqual(files[2].meta)
+
 expect(files).toEqual([
   {
     path: 'home',
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 24f18a1 and 4b66770.

📒 Files selected for processing (1)
  • packages/nuxt/test/pages.test.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (20)
  • GitHub Check: test-fixtures (ubuntu-latest, built, webpack, default, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, webpack, async, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, rspack, default, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, rspack, async, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-off, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-off, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, js, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-off, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-off, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, js, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, json, 18)
  • GitHub Check: typecheck (windows-latest, node)
  • GitHub Check: test-benchmark
  • GitHub Check: typecheck (windows-latest, bundler)
  • GitHub Check: release-pr
  • GitHub Check: typecheck (ubuntu-latest, node)
  • GitHub Check: typecheck (ubuntu-latest, bundler)
🔇 Additional comments (1)
packages/nuxt/test/pages.test.ts (1)

838-874: Well-structured test suite for page extension functionality.

The test suite effectively verifies the handling of route metadata when multiple entries reference the same file but have different metadata configurations. The implementation follows good testing practices with clear setup and assertions.

@xjccc xjccc changed the title fix(nuxt): add unique cacheKey with getRouteMeta fix(nuxt): use klona to deep clone extractedMeta Jan 24, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (2)
packages/nuxt/test/pages.test.ts (2)

840-845: Consider renaming the test to enhance clarity.
Although the current test name is acceptable, a more descriptive name (e.g. “should preserve distinct metadata for multiple routes referencing the same file”) may convey the scenario more clearly.

Here is a possible update:

-  it('should correct route metadata by same file with different metadata', async () => {
+  it('should preserve distinct metadata for multiple routes referencing the same file', async () => {

856-873: Confirm the correctness of deep object comparisons.
toEqual is acceptable for this scenario, but if more exact checking is needed (especially for object prototype verifications), toStrictEqual could be used. For now, this is sufficiently robust.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between eeb81dd and a206c58.

📒 Files selected for processing (1)
  • packages/nuxt/test/pages.test.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (18)
  • GitHub Check: test-fixtures (windows-latest, built, rspack, default, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, webpack, default, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, webpack, async, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, rspack, default, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, rspack, async, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-off, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, default, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-off, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, js, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, built, vite, async, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-off, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, default, manifest-on, json, 18)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-off, json, 18)
  • GitHub Check: typecheck (windows-latest, node)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, js, 18)
  • GitHub Check: typecheck (windows-latest, bundler)
  • GitHub Check: test-fixtures (ubuntu-latest, dev, vite, async, manifest-on, json, 18)
  • GitHub Check: test-benchmark
🔇 Additional comments (2)
packages/nuxt/test/pages.test.ts (2)

838-839: Test suite appears well-structured.
No issues identified with the creation of the page:extends suite or the constant declaration.


846-855: Virtual file system usage is effective.
The approach for constructing the virtual file system and passing it to augmentPages is clean. There are no concurrency or performance concerns here.

@danielroe danielroe merged commit b205d8d into nuxt:main Jan 24, 2025
48 checks passed
@github-actions github-actions bot mentioned this pull request Jan 24, 2025
@github-actions github-actions bot mentioned this pull request Jan 24, 2025
@xjccc xjccc deleted the fix/30695 branch January 25, 2025 03:00
Kamsou pushed a commit to Kamsou/nuxt that referenced this pull request Feb 5, 2025
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.

experimental.scanPageMeta 'after-resolve' combines metas from same-file routes
2 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy