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 runtime typechecks for sortable IDs and items. #734

Closed
wants to merge 1 commit into from

Conversation

qrohlf
Copy link

@qrohlf qrohlf commented May 13, 2022

Marking this as a draft because I still need to NPM link this into my project and manually test it.

Resolves #606

@changeset-bot
Copy link

changeset-bot bot commented May 13, 2022

⚠️ No Changeset found

Latest commit: b93fe8a

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

// the process.env guard will cause this check to be removed from the bundle
// at build time by most modern build tools
if (process.env.NODE_ENV !== 'production') {
if (items.every((i) => typeof id === 'string')) {
Copy link
Author

Choose a reason for hiding this comment

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

Because SortableContext is relatively high up in the render tree, I don't think this will cause perf issues in development but because it's iterating over the items array, it does have the potential to.

This check could be memoized but it would need to use something besides React.useMemo in order to avoid the hooks linter complaining about hooks inside a conditional (even if that conditional will never change at runtime...)

@clauderic
Copy link
Owner

Hey @qrohlf, thanks for opening a PR ❤️

I have a different solution in mind to this problem so I will be closing this PR for the time being #755

Feel free to re-open an issue to discuss if you feel like #755 doesn't fully address your concerns.

@clauderic clauderic closed this May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Throw a descriptive error in development when non-string IDs are passed to useSortable or SortableContext
2 participants