Skip to content

🐛(layout): Update parameter parsing in layout components to await params #1572

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 1 commit into from
May 1, 2025

Conversation

MH4GF
Copy link
Member

@MH4GF MH4GF commented May 1, 2025

Issue

  • Fixes NextJS warning about synchronous dynamic APIs

Why is this change needed?

NextJS warns about using params without awaiting it first. This PR fixes the warning by properly awaiting the params object before accessing its properties.

The following warning was shown:

Error: Route "/app/projects/[projectId]/ref/[branchOrCommit]/schema-poc" used `params.projectId`. `params` should be awaited before using its properties. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis

What would you like reviewers to focus on?

  • Confirm this is the correct way to handle params in Next.js async layouts and pages

Testing Verification

  • Verified that the warning no longer appears
  • Verified that the layout and routing functionality works as expected

What was done

🤖 Generated by PR Agent at f52bbaf

  • Fix parameter parsing by awaiting params in layout and page components
  • Resolve Next.js warning about synchronous dynamic API usage
  • Ensure proper validation of route parameters in affected files

Detailed Changes

Relevant files
Bug fix
layout.tsx
Await params before parsing in project layout                       

frontend/apps/app/app/(app)/app/(with-project)/projects/[projectId]/layout.tsx

  • Await params before parsing in layout component
  • Ensures parameter validation is performed on resolved params
  • +1/-1     
    layout.tsx
    Await params before parsing in branch layout                         

    frontend/apps/app/app/(app)/app/(with-project-and-branch)/projects/[projectId]/ref/[branchOrCommit]/layout.tsx

  • Await params before parsing in layout component
  • Fixes parameter validation for dynamic routes
  • +1/-1     
    page.tsx
    Await params before parsing in branch page                             

    frontend/apps/app/app/(app)/app/(with-project-and-branch)/projects/[projectId]/ref/[branchOrCommit]/page.tsx

  • Await params before parsing in page component
  • Ensures error is thrown only after params are resolved and validated
  • +1/-1     

    Additional Notes

    None


    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • fix following warning:
    ```
    Error: Route "/app/projects/[projectId]/ref/[branchOrCommit]/schema-poc" used `params.projectId`. `params` should be awaited before using its properties. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
        at Layout (webpack-internal:/(rsc)/app/(app)/app/(with-project-and-branch)/projects/[projectId]/ref/[branchOrCommit]/app/(app)/app/(with-project-and-branch)/projects/[projectId]/ref/[branchOrCommit]/layout.tsx:14:23)
        at Object.apply (webpack-internal:/(rsc)/app/(app)/app/(with-project-and-branch)/projects/[projectId]/ref/[branchOrCommit]/sentry-wrapper-module:44:9)
      12 |
      13 | export default async function Layout({ params, children }: LayoutProps) {
    > 14 |   const parsedParams = v.safeParse(paramsSchema, params)
         |                       ^
      15 |   if (!parsedParams.success) {
      16 |     // TODO: Reconsider the display when parse fails
      17 |     return children
    ```
    @MH4GF MH4GF requested a review from a team as a code owner May 1, 2025 06:05
    @MH4GF MH4GF requested review from hoshinotsuyoshi, FunamaYukina, junkisai and NoritakaIkeda and removed request for a team May 1, 2025 06:05
    Copy link

    changeset-bot bot commented May 1, 2025

    ⚠️ No Changeset found

    Latest commit: f52bbaf

    Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

    This PR includes no changesets

    When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

    Click here to learn what changesets are, and how to add one.

    Click here if you're a maintainer who wants to add a changeset to this PR

    Copy link

    vercel bot commented May 1, 2025

    The latest updates on your projects. Learn more about Vercel for Git ↗︎

    Name Status Preview Comments Updated (UTC)
    liam-app ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 1, 2025 6:10am
    liam-erd-sample ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 1, 2025 6:10am
    1 Skipped Deployment
    Name Status Preview Comments Updated (UTC)
    liam-docs ⬜️ Ignored (Inspect) May 1, 2025 6:10am

    Copy link

    supabase bot commented May 1, 2025

    Updates to Preview Branch (fix-layout-props) ↗︎

    Deployments Status Updated
    Database Thu, 01 May 2025 06:08:11 UTC
    Services Thu, 01 May 2025 06:08:11 UTC
    APIs Thu, 01 May 2025 06:08:11 UTC

    Tasks are run on every commit but only new migration files are pushed.
    Close and reopen this PR if you want to apply changes from existing seed or migration files.

    Tasks Status Updated
    Configurations Thu, 01 May 2025 06:08:16 UTC
    Migrations Thu, 01 May 2025 06:08:18 UTC
    Seeding Thu, 01 May 2025 06:08:18 UTC
    Edge Functions Thu, 01 May 2025 06:08:18 UTC

    View logs for this Workflow Run ↗︎.
    Learn more about Supabase for Git ↗︎.

    Copy link
    Contributor

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ No major issues detected

    Copy link
    Contributor

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    General
    Remove unnecessary await

    The params object is likely not a Promise and doesn't need to be awaited. Using
    await on a non-Promise object is unnecessary and could lead to unexpected
    behavior. Remove the await keyword unless you're certain that params is a
    Promise.

    frontend/apps/app/app/(app)/app/(with-project)/projects/[projectId]/layout.tsx [11]

    -const parsedParams = v.safeParse(paramsSchema, await params)
    +const parsedParams = v.safeParse(paramsSchema, params)
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    __

    Why: The suggestion correctly identifies that the params object in Next.js layouts/pages is not a Promise, making the await keyword added in the PR unnecessary and potentially confusing. Removing it reverts to the correct usage.

    Medium
    Learned
    best practice
    Improve error message specificity

    The error message is too generic and doesn't provide information about which
    parameter failed validation. Include more specific details about the validation
    failure to aid in debugging and troubleshooting.

    frontend/apps/app/app/(app)/app/(with-project-and-branch)/projects/[projectId]/ref/[branchOrCommit]/page.tsx [13-14]

     const parsedParams = v.safeParse(paramsSchema, await params)
    -if (!parsedParams.success) throw new Error('Invalid parameters')
    +if (!parsedParams.success) throw new Error(`Invalid parameters: ${parsedParams.error.message}`)
    • Apply this suggestion
    Suggestion importance[1-10]: 6
    Low
    • More

    Copy link
    Member

    @NoritakaIkeda NoritakaIkeda left a comment

    Choose a reason for hiding this comment

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

    LGTM!

    @NoritakaIkeda NoritakaIkeda added this pull request to the merge queue May 1, 2025
    Merged via the queue into main with commit 54af747 May 1, 2025
    21 checks passed
    @NoritakaIkeda NoritakaIkeda deleted the fix-layout-props branch May 1, 2025 06:17
    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.

    2 participants