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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions examples/nextjs-spa/src/pages/recovery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,7 @@ const Recovery: NextPageWithLayout = () => {
updateRecoveryFlowBody: values,
})
.then(({ data }) => {
// reset the form data completely
setFlow(null)
// Form submission was successful, show the message to the user!
getFlow(data.id)
Comment on lines -87 to -90
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.

setFlow(data)
})
.catch(handleError)

Expand Down
4 changes: 1 addition & 3 deletions examples/nextjs-spa/src/pages/verification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,8 @@ const Verification: NextPageWithLayout = () => {
updateVerificationFlowBody: values,
})
.then(({ data }) => {
// reset the input fields
setFlow(null)
// Form submission was successful, show the message to the user!
getFlow(data.id)
setFlow(data)
})
.catch(handleError)

Expand Down
3 changes: 1 addition & 2 deletions examples/preact-spa/src/recovery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export const Recovery = () => {
})
.then(({ data: flow }) => {
// Form submission was successful, show the message to the user!
setFlow(null)
getFlow(flow.id)
setFlow(flow)
})
.catch(sdkErrorHandler)
}
Expand Down
3 changes: 1 addition & 2 deletions examples/preact-spa/src/verification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ export const Verification = () => {
updateVerificationFlowBody: body,
})
.then(({ data: flow }) => {
setFlow(null)
getFlow(flow.id)
setFlow(flow)
})
.catch(sdkErrorHandler)
}
Expand Down
3 changes: 1 addition & 2 deletions examples/react-spa/src/Recovery.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ export const Recovery = () => {
.updateRecoveryFlow({ flow: flow.id, updateRecoveryFlowBody: body })
.then(({ data: flow }) => {
// Form submission was successful, show the message to the user!
setFlow(null)
getFlow(flow.id)
setFlow(flow)
})
.catch(sdkErrorHandler)
}
Expand Down
3 changes: 1 addition & 2 deletions examples/react-spa/src/Verification.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ export const Verification = (): JSX.Element => {
updateVerificationFlowBody: body,
})
.then(({ data: flow }) => {
setFlow(null)
getFlow(flow.id)
setFlow(flow)
})
.catch(sdkErrorHandler)
}
Expand Down
37 changes: 24 additions & 13 deletions src/react-components/ory/helpers/filter-flow-nodes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import {
FilterNodesByGroups,
filterNodesByGroups,
getNodeInputType,
isUiNodeAnchorAttributes,
isUiNodeImageAttributes,
isUiNodeInputAttributes,
isUiNodeScriptAttributes,
isUiNodeTextAttributes,
} from "@ory/integrations/ui"
import { JSX } from "react"

Expand All @@ -25,20 +29,27 @@ export const FilterFlowNodes = ({

const nodes = filterNodesByGroups(filter)
// we don't want to map the csrf token every time, only on the form level
.filter((node) =>
getInputName(node) === "csrf_token" && !includeCSRF ? false : true,
)
.map((node, k) =>
["hidden"].includes(getNodeInputType(node.attributes))
? {
node: <Node node={node} key={k} {...overrides} />,
hidden: true,
.filter((node) => includeCSRF || !(getInputName(node) === "csrf_token"))
.map((node, k) => ({
node: (
<Node
node={node}
key={
isUiNodeInputAttributes(node.attributes)
? node.attributes.name
: isUiNodeImageAttributes(node.attributes)
? node.attributes.src
: isUiNodeAnchorAttributes(node.attributes) ||
isUiNodeTextAttributes(node.attributes) ||
isUiNodeScriptAttributes(node.attributes)
? node.attributes.id
: k
}
: {
node: <Node node={node} key={k} {...overrides} />,
hidden: false,
},
)
{...overrides}
/>
),
hidden: getNodeInputType(node.attributes) === "hidden",
}))
return nodes.length > 0 ? (
<>
{nodes.filter((node) => node.hidden).map((node) => node.node)}
Expand Down
Loading