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

RouteObject with index=true should not accept children. #9343

Closed
wants to merge 5 commits into from

Conversation

GuptaSiddhant
Copy link
Contributor

RouteObject type should accept either index or children but not both, since an index route cannot has children.

@changeset-bot
Copy link

changeset-bot bot commented Sep 25, 2022

⚠️ No Changeset found

Latest commit: 109cead

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

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Sep 25, 2022

Hi @GuptaSiddhant,

Welcome, and thank you for contributing to React Router!

Before we consider your pull request, we ask that you sign our Contributor License Agreement (CLA). We require this only once.

You may review the CLA and sign it by adding your name to contributors.yml.

Once the CLA is signed, the CLA Signed label will be added to the pull request.

If you have already signed the CLA and received this response in error, or if you have any questions, please contact us at hello@remix.run.

Thanks!

- The Remix team

@remix-cla-bot
Copy link
Contributor

remix-cla-bot bot commented Sep 25, 2022

Thank you for signing the Contributor License Agreement. Let's get this merged! 🥳

@GuptaSiddhant GuptaSiddhant changed the title Add conditional type to RouteObject RouteObject with index=true should not accept children. Sep 25, 2022
@GuptaSiddhant
Copy link
Contributor Author

If accepted, the docs could be updated to reflect the new RouteObject type.
https://reactrouter.com/en/main/route/route#type-declaration

@timdorr
Copy link
Member

timdorr commented Sep 26, 2022

Can you add some tests to this?

@@ -584,7 +584,7 @@ export function createRoutesFromChildren(
handle: element.props.handle,
};

if (element.props.children) {
if (element.props.children && !route.index) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be better to use an invariant here so that the error is identified and surfaced to the user, instead of silently skipping children in a mismatched scenario?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add the invariant.

@brophdawg11 brophdawg11 self-assigned this Sep 27, 2022
@GuptaSiddhant
Copy link
Contributor Author

Can you add some tests to this?

A test is added.

@brophdawg11
Copy link
Contributor

@GuptaSiddhant Do you mind rebasing this and re-pointing to the dev branch since it contains code changes with the invariants?

@GuptaSiddhant
Copy link
Contributor Author

@GuptaSiddhant Do you mind rebasing this and re-pointing to the dev branch since it contains code changes with the invariants?

@brophdawg11 Rebased and pointing to "dev"

@brophdawg11
Copy link
Contributor

brophdawg11 commented Sep 28, 2022

Thank you for this PR @GuptaSiddhant! I dug into this a bit more and this idea can actually be extended both upwards and downwards to get the same type safety inside @remix-run/router and on <Route>'s RouteProps.

To make sure we don't lose your contribution I cherry-picked your commits into a new PR (so you retain authorship) and added the additional typing changes on top of them, and we'll get this work merged via that PR.

Here's the new PR: #9366

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.

4 participants