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

Add test for providing correct params to layouts #43775

Conversation

jankaifer
Copy link
Contributor

@jankaifer jankaifer commented Dec 6, 2022

  • Add test ensuring that layout gets only params that are relevant for that layout
  • Add tests for catchall params

@timneutkens timneutkens merged commit 2022fa6 into vercel:canary Dec 7, 2022
@jankaifer jankaifer deleted the jankaifer/nex-102-add-test-for-only-providing-segments branch December 8, 2022 15:59
@trevorpfiz
Copy link

Are there known issues with params "leaking" into other routes? I noticed some issues when my previewData() implementation was breaking.

Is this a flawed implementation of the bottom up approach? When I console.log(params) I am getting the params for every post.

export async function generateStaticParams() {
  const paths = await getAllPostsSlugs();

  function loopParams(posts: Post[]) {
    const params: { courseSlug: string; sectionSlug: string; postSlug: string }[] = [];

    posts.forEach((post) => {
      const postSlug = post?.slug;
      post?.sections?.forEach((section) => {
        const sectionSlug = section?.slug;
        section?.courses?.forEach((course) => {
          const courseSlug = course?.slug;

          params.push({ courseSlug, sectionSlug, postSlug });
        });
      });
    });

    return params;
  }

  return loopParams(paths);
}

Let's say I have a post 1 and 2.
If I visit /course/section/1, I get:

{
  courseSlug: 'course',
  sectionSlug: 'section',
  postSlug: '1'
}
{
  courseSlug: 'course',
  sectionSlug: 'section',
  postSlug: '2'
}

Instead of just:

{
  courseSlug: 'course',
  sectionSlug: 'section',
  postSlug: '1'
}

@jankaifer
Copy link
Contributor Author

@ElektrikSpark Could you open a new issue for this, please?

To answer your question - we don't know about any param leaking.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants