Skip to content

Conversation

@fezproof
Copy link
Contributor

Changes

Issue: NodeType in NodeBase always resolves to be potentially undefined.

Solution: Update the NodeBase type to have a stronger NodeType field that can be undefined only if you don't specify it.

Use case

Current behaviour
image

Desired behaviour
image

This also now works for union types:
image

Version info

I consider this type issue a bug, but you probably want to link it to a minor version update to not shock people if the type suddenly change. Up to you though :)

Update the NodeBase type to have a stronger NodeType field that can be undefined even if you specifically define it.
@changeset-bot
Copy link

changeset-bot bot commented Sep 17, 2024

⚠️ No Changeset found

Latest commit: 9f7bc8c

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

@moklick
Copy link
Member

moklick commented Sep 17, 2024

Hey @fezproof thanks for your input here. Why did you close the PR?

@fezproof fezproof reopened this Sep 17, 2024
@fezproof
Copy link
Contributor Author

Hey @fezproof thanks for your input here. Why did you close the PR?

Sorry didn’t mean to!

@bcakmakoglu
Copy link
Contributor

My 2 cents: this change would mean that user could not omit type anymore (which probably isn't a big deal for most users) to use the default node type without explicitly defining it as default.

For example:

    { id: 'a', type: 'input', position: { x: 0, y: 0 }, data: { label: 'wire' } }, // <--- this node is fine
    { id: 'b', position: { x: -100, y: 100 }, data: { label: 'drag me!' }, }, // <--- this node gives an error because `type` property is missing

@moklick
Copy link
Member

moklick commented Sep 17, 2024

I checked this again and unfortunately we can't make this change because it would be a breaking change. In a lot of examples (and real world apps), nodes do not have a type and all those apps would break.

@fezproof
Copy link
Contributor Author

Let me have another crack at this, I am sure I can get this to work

… ones

Updated svelte and react packages to accommodate this
@fezproof
Copy link
Contributor Author

@moklick @bcakmakoglu I have taken a second pass at this and updated the generic to be able to handle both defined and undefined NodeType. If undefined, it will fall back to the original definition.
All the repo now pass typechecks + it builds and passes tests.

@fezproof
Copy link
Contributor Author

Hey @moklick and @bcakmakoglu, does those changes fix your concerns?

@peterkogo
Copy link
Member

@fezproof Can you please explain what undefined extends NodeType really does? Or do you have some pointer to the official documentation.

@RichSchulz
Copy link
Contributor

RichSchulz commented Oct 11, 2024

@fezproof Can you please explain what undefined extends NodeType really does? Or do you have some pointer to the official documentation.

The way I understand this it checks whether the type provided as NodeType is undefined (i.e. no type provided) or can be undefined (e.g. "input" | "output" | undefined), and then propagates this information correctly to the type property of the NodeBase type (be either making it optional or not).

@fezproof is this what you intended?

@RichSchulz
Copy link
Contributor

Hey @moklick are there more concerns from your side regarding this PR? This PR would make upgrading to xyflow 12 for us much more easy :)

@moklick
Copy link
Member

moklick commented May 12, 2025

As @RichSchulz pointed out, this makes the migration to v12 easier for some users so we should check this again,

@moklick moklick merged commit 9f7bc8c into xyflow:main May 20, 2025
@moklick
Copy link
Member

moklick commented May 20, 2025

Thanks again @fezproof ! Took a bit longer than expected, but this will land in the next release 🚀
And thanks @RichSchulz for the kindly reminder :)

@moklick
Copy link
Member

moklick commented Jun 11, 2025

finally merged and released with 12.7.0 🙌 Thanks @fezproof!

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.

5 participants