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

fix: use unique keys for flow nodes #159

Merged
merged 2 commits into from
Oct 11, 2023
Merged

fix: use unique keys for flow nodes #159

merged 2 commits into from
Oct 11, 2023

Conversation

zepatrik
Copy link
Member

@zepatrik zepatrik commented Oct 10, 2023

Closes #78 for real.

Comment on lines -87 to -90
// reset the form data completely
setFlow(null)
// Form submission was successful, show the message to the user!
getFlow(data.id)
Copy link
Member Author

Choose a reason for hiding this comment

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

Reverting all of these changes from 85cc979 because they just masked the real issue.

Comment on lines 33 to 43
key={
// input node
"name" in node.attributes
? node.attributes.name
: // image node
"src" in node.attributes
? node.attributes.src
: // anchor, text & script node
"id" in node.attributes
? node.attributes.id
: k
Copy link
Member Author

Choose a reason for hiding this comment

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

This is the real fix. Previously a re-render after a flow was updated resulted in the same keys, although the input was vastly different. Because the mapping key here was the same, react did not properly re-render the input fields.
This is why index-based keys are always a bit tricky and should only be used when you are absolutely sure that the other props never change across re-renders.

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense!

Comment on lines 33 to 43
key={
// input node
"name" in node.attributes
? node.attributes.name
: // image node
"src" in node.attributes
? node.attributes.src
: // anchor, text & script node
"id" in node.attributes
? node.attributes.id
: k
Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense!

node={node}
key={
// input node
"name" in node.attributes
Copy link
Contributor

Choose a reason for hiding this comment

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

don't we have TypeGuards for this? I believe we already use ory/integrations here, so might as well use the TypeGuards?

https://github.com/ory/integrations/blob/main/src/ui/index.ts#L87

https://github.com/ory/integrations/blob/main/src/ui/index.ts#L54

Copy link
Member Author

Choose a reason for hiding this comment

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

Good call 👍

@zepatrik zepatrik merged commit 4bdbac1 into main Oct 11, 2023
10 checks passed
@zepatrik zepatrik deleted the fix/recovery-state branch October 11, 2023 07:35
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.

Recovery flow: email address stays filled in the code field
2 participants