# Link-out link-in in subflows, after copy

**URL:** <https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506>\
**Category:** General\
**Created:** [4 June 2024 18:38 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506 "2024-06-04T18:38:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![zba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zba/32/91182_2.png) [@zba](https://discourse.nodered.org/u/zba)\
**Post date:** [4 June 2024 18:38 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/1 "2024-06-04T18:38:29Z")

</div>

I have a template to connect my device inside, it uses link-out link-in nodes, when I cloned it using export/import I lost all link connections inside, same if I try to copy/paste linked nodes to other subflow, is it something with my setup, or node-red does not recalculate link ids on copy/paste and export ? It makes link usage very limited and make me think to refactor all back to wires.

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [4 June 2024 18:42 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/2 "2024-06-04T18:42:15Z")

</div>

Please can you give an example to debug it.

---

<div class="post-metadata">

**Author:** ![zba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zba/32/91182_2.png) [@zba](https://discourse.nodered.org/u/zba)\
**Post date:** [4 June 2024 18:43 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/3 "2024-06-04T18:43:21Z")

</div>

Yes, one second, just found that it was bug already [Export/import links disconnected in subflows · Issue #4055 · node-red/node-red · GitHub](https://github.com/node-red/node-red/issues/4055)

so collecting info, my node is

version: 3.1.9

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [4 June 2024 18:57 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/4 "2024-06-04T18:57:52Z")

</div>

That issue is closed as "fixed" see comment: [Export/import links disconnected in subflows · Issue #4055 · node-red/node-red · GitHub](https://github.com/node-red/node-red/issues/4055#issuecomment-1451938797)

So either there is a regression or is a different problem.  
Can you confirm the steps in that issue are exactly the same as you are seeing in v3.1.9?

---

<div class="post-metadata">

**Author:** ![zba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zba/32/91182_2.png) [@zba](https://discourse.nodered.org/u/zba)\
**Post date:** [4 June 2024 19:05 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/5 "2024-06-04T19:05:18Z")

</div>

so reproduced it, follow this simple steps to repeat:

- import provided code
- in Subflow1 there is function and another subflow - export it, and import with view-nodes... copy checkboxed to the same Subflow1
- check copy and original - in my case they disconnected

> **code**
>
> ```json
> [
> {
> "id": "671fd229d55cc4d1",
> "type": "subflow",
> "name": "have links inside",
> "info": "",
> "category": "",
> "in": [
> {
> "x": 80,
> "y": 100,
> "wires": [
> {
> "id": "a39dc90d7144616f"
> }
> ]
> }
> ],
> "out": [
> {
> "x": 640,
> "y": 100,
> "wires": [
> {
> "id": "29c751aab0f9300f",
> "port": 0
> }
> ]
> },
> {
> "x": 640,
> "y": 240,
> "wires": [
> {
> "id": "47ce190f78c786b2",
> "port": 0
> }
> ]
> }
> ],
> "env": [],
> "meta": {},
> "color": "#DDAA99"
> },
> {
> "id": "e8309cbccae18876",
> "type": "function",
> "z": "671fd229d55cc4d1",
> "g": "3d47e1b41cda7dc4",
> "name": "doing something",
> "func": "\nreturn [msg];",
> "outputs": 2,
> "timeout": 0,
> "noerr": 0,
> "initialize": "",
> "finalize": "",
> "libs": [],
> "x": 380,
> "y": 140,
> "wires": [
> [
> "e3d3966e1fd317f1"
> ],
> [
> "dbcb9707ca5d578d"
> ]
> ]
> },
> {
> "id": "49b8775d8a0e2462",
> "type": "link in",
> "z": "671fd229d55cc4d1",
> "g": "3d47e1b41cda7dc4",
> "name": "link in 1",
> "links": [
> "a39dc90d7144616f"
> ],
> "x": 225,
> "y": 140,
> "wires": [
> [
> "e8309cbccae18876"
> ]
> ]
> },
> {
> "id": "a39dc90d7144616f",
> "type": "link out",
> "z": "671fd229d55cc4d1",
> "name": "link out 1",
> "mode": "link",
> "links": [
> "49b8775d8a0e2462"
> ],
> "x": 145,
> "y": 100,
> "wires": []
> },
> {
> "id": "e3d3966e1fd317f1",
> "type": "link out",
> "z": "671fd229d55cc4d1",
> "g": "3d47e1b41cda7dc4",
> "name": "link out 2",
> "mode": "link",
> "links": [
> "29c751aab0f9300f"
> ],
> "x": 495,
> "y": 120,
> "wires": [],
> "icon": "font-awesome/fa-thumbs-up"
> },
> {
> "id": "29c751aab0f9300f",
> "type": "link in",
> "z": "671fd229d55cc4d1",
> "name": "link in 2",
> "links": [
> "e3d3966e1fd317f1"
> ],
> "x": 575,
> "y": 100,
> "wires": [
> []
> ],
> "icon": "font-awesome/fa-thumbs-up"
> },
> {
> "id": "dbcb9707ca5d578d",
> "type": "link out",
> "z": "671fd229d55cc4d1",
> "g": "3d47e1b41cda7dc4",
> "name": "link out 3",
> "mode": "link",
> "links": [
> "47ce190f78c786b2"
> ],
> "x": 495,
> "y": 160,
> "wires": []
> },
> {
> "id": "47ce190f78c786b2",
> "type": "link in",
> "z": "671fd229d55cc4d1",
> "name": "link in 3",
> "links": [
> "dbcb9707ca5d578d"
> ],
> "x": 585,
> "y": 240,
> "wires": [
> []
> ]
> },
> {
> "id": "3d47e1b41cda7dc4",
> "type": "group",
> "z": "671fd229d55cc4d1",
> "style": {
> "stroke": "#999999",
> "stroke-opacity": "1",
> "fill": "none",
> "fill-opacity": "1",
> "label": true,
> "label-position": "nw",
> "color": "#a4a4a4"
> },
> "nodes": [
> "e8309cbccae18876",
> "49b8775d8a0e2462",
> "e3d3966e1fd317f1",
> "dbcb9707ca5d578d"
> ],
> "x": 184,
> "y": 79,
> "w": 352,
> "h": 122
> },
> {
> "id": "2ba1654070afcce1",
> "type": "subflow",
> "name": "Subflow 1",
> "info": "",
> "in": [],
> "out": []
> },
> {
> "id": "59950c9dfd1e8cb5",
> "type": "function",
> "z": "2ba1654070afcce1",
> "name": "function 2",
> "func": "\nreturn msg;",
> "outputs": 1,
> "timeout": 0,
> "noerr": 0,
> "initialize": "",
> "finalize": "",
> "libs": [],
> "x": 240,
> "y": 100,
> "wires": [
> []
> ]
> },
> {
> "id": "18c2d4fa0a5a3f2a",
> "type": "subflow:671fd229d55cc4d1",
> "z": "2ba1654070afcce1",
> "name": "",
> "x": 260,
> "y": 200,
> "wires": [
> [],
> []
> ]
> },
> {
> "id": "f7e36cb09e5e6b5b",
> "type": "subflow:2ba1654070afcce1",
> "z": "3c4154b39eca0635",
> "name": "",
> "x": 500,
> "y": 860,
> "wires": []
> }
> ]
> 
> ```

> **screenshots**
>
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/6/76734a65d64ee1beb16e33e85ad0c3bde7d18218.png)  
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/6/f603938cf0a5d49150f81b34a8c179cf18261b08.png)
> 
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/d/edfbce683c9be28f941bfbd4f948e2c81ed670d3.png)  
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/7/c7fd910af7060ebd8d4b5d7b19199660eb7ea5b1.png)

upd, same will happen if you copy all from subflow with links and paste it to any other subflow (not top flow)

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [4 June 2024 19:12 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/6 "2024-06-04T19:12:24Z")

</div>

I confirm, I know why - will add the reason to the issue

---

<div class="post-metadata">

**Author:** ![zba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zba/32/91182_2.png) [@zba](https://discourse.nodered.org/u/zba)\
**Post date:** [4 June 2024 19:15 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/7 "2024-06-04T19:15:09Z")

</div>

while reproducing, I think I found workaround - to clone to top flow and then just copy inside subflow as initialised node ?

upd: another issue with import - can't import subflow to itself, even if importing copy, I think it is not fair 🙂 while may be not much use case.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [4 June 2024 19:55 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/8 "2024-06-04T19:55:08Z")

</div>

> [@zba](#):
>
> can't import subflow to itself

That would give you an infinite set of subflows inside each other, as each one would include another copy inside.

---

<div class="post-metadata">

**Author:** ![zba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zba/32/91182_2.png) [@zba](https://discourse.nodered.org/u/zba)\
**Post date:** [4 June 2024 22:44 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/9 "2024-06-04T22:44:39Z")

</div>

I mean, if I mark to clone all I copy, it shall just copy, there shall be no infinity, because it I clone parent too, and Import it from hardcopy of "exported json"... there shall be no real link between what I paste and where I paste.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [5 June 2024 05:59 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/10 "2024-06-05T05:59:29Z")

</div>

Sorry, I have no idea what you mean. Please explain exactly what you are unable to do.

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [5 June 2024 10:31 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/11 "2024-06-05T10:31:19Z")

</div>

> <https://github.com/node-red/node-red/pull/4750>
>
> \- \[x\] Bugfix (non-breaking change which fixes an issue)
> \- \[\] New feature (non-…breaking change which adds functionality)
> 
> \## Proposed changes
> 
> Fixes #4749.
> 
> Fixes \`node\_map\` does not contain as key the new id of a copied node.
> 
> \## Checklist
> 
> \- \[x\] I have read the \[contribution guidelines\](https://github.com/node-red/node-red/blob/master/CONTRIBUTING.md)
> \- \[\] For non-bugfix PRs, I have discussed this change on the forum/slack team.
> \- \[x\] I have run \`npm run test\` to verify the unit tests pass
> \- \[\] I have added suitable unit tests to cover the new/changed functionality

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [5 June 2024 10:33 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/12 "2024-06-05T10:33:35Z")

</div>

Sorry, I can't give you a solution.

But to let you know:

I have had this problem myself - a LONG TIME AGO!

Alas I am not able to remember how I fixed it.

Could you tell us the version of NR you are running?

---

<div class="post-metadata">

**Author:** ![zba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zba/32/91182_2.png) [@zba](https://discourse.nodered.org/u/zba)\
**Post date:** [5 June 2024 18:20 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/13 "2024-06-05T18:20:57Z")

</div>

@Colin I already explained, but ok, screenshots for you.

> **screens**
>
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/3/2/32ea82343148d48403d29e8ebc6e45395f1f0149.png)  
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/9/b96e69bee19f5e9075f571368a050eba0cd51f76.png)
> 
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/3/733bafedfa345801bfbbc2bfca2395ea575a15ef.png)  
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/c/6c9350595191bdb28ae8ccd6326c06d74ddd07bc.png)

Next step, I making **full copy** of Subflow2, so assume it shall be important without problems.

> **screens**
>
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/7/8735f3e332e41f0cdef7f9ce01fbb973ea31b04d.png)  
> ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/7/7/77c266862e524f7ec61d9f140b044ab067345b2b.png)

I assume it wrong behavior, because if I import to top flow 1st and copy result subflow to "itself", I not getting any errors and expect exactly same if I import being inside subflow. It is not critical, but points to some mess in order of node creation and register inside subflow. May be above patch will fix this because it seems related.

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [5 June 2024 18:27 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/14 "2024-06-05T18:27:20Z")

</div>

Uh, you want to copy a subflow inside the subflow?

---

<div class="post-metadata">

**Author:** ![zba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zba/32/91182_2.png) [@zba](https://discourse.nodered.org/u/zba)\
**Post date:** [5 June 2024 18:31 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/15 "2024-06-05T18:31:40Z")

</div>

No, I not want copy, just found this while repeating bug with import links, I think it just unexpected, that it have error at this moment, because logically - things I importing are not part of current flow, just having similar ids.

It can became inconvinience in some rare cases, like if you had a template function and importing it to several places, finally it can happen that you import "template" to subflow which was source of such template (or first instance). I bet one who get this will think a lot "why complete different function is "itself" ?"

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [5 June 2024 18:37 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/16 "2024-06-05T18:37:38Z")

</div>

Mmm, can you please give us a list of steps to follow to see the problem.

Because the second image is misleading.

---

<div class="post-metadata">

**Author:** ![zba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zba/32/91182_2.png) [@zba](https://discourse.nodered.org/u/zba)\
**Post date:** [5 June 2024 18:42 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/17 "2024-06-05T18:42:41Z")

</div>

In second image I just click "edit subflow" for Subflow2, after exporting it. Not sure what missleading. Subflow itself is just dummy "create subflow" from "function" nothing inside

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [5 June 2024 18:48 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/18 "2024-06-05T18:48:44Z")

</div>

But why? Where (flow/subflow tab) you have imported the subflow?

---

<div class="post-metadata">

**Author:** ![zba](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zba/32/91182_2.png) [@zba](https://discourse.nodered.org/u/zba)\
**Post date:** [5 June 2024 18:51 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/19 "2024-06-05T18:51:50Z")

</div>

Yes, Inside the subflow, sorry for misscommunication (I not want to copy subflow inside itself, but I tried)

This is result I expect to receive when doing so

> **flow**
>
> ```json
> [
> {
> "id": "ba2c0867ebceaeac",
> "type": "subflow",
> "name": "Subflow 2",
> "info": "",
> "in": [],
> "out": []
> },
> {
> "id": "ce10381db1559d8d",
> "type": "function",
> "z": "ba2c0867ebceaeac",
> "name": "function 3",
> "func": "\nreturn msg;",
> "outputs": 1,
> "timeout": 0,
> "noerr": 0,
> "initialize": "",
> "finalize": "",
> "libs": [],
> "x": 200,
> "y": 80,
> "wires": [
> []
> ]
> },
> {
> "id": "4875d2d320e854a1",
> "type": "subflow",
> "name": "Subflow 2",
> "info": "",
> "in": [],
> "out": []
> },
> {
> "id": "3c6908f4a035f01f",
> "type": "function",
> "z": "4875d2d320e854a1",
> "name": "function 3",
> "func": "\nreturn msg;",
> "outputs": 1,
> "timeout": 0,
> "noerr": 0,
> "initialize": "",
> "finalize": "",
> "libs": [],
> "x": 200,
> "y": 80,
> "wires": [
> []
> ]
> },
> {
> "id": "9ed73a9016d9b75c",
> "type": "subflow:ba2c0867ebceaeac",
> "z": "4875d2d320e854a1",
> "name": "",
> "x": 260,
> "y": 180,
> "wires": []
> },
> {
> "id": "99aedb3212b835d3",
> "type": "subflow:4875d2d320e854a1",
> "z": "3c4154b39eca0635",
> "name": "",
> "x": 360,
> "y": 980,
> "wires": []
> }
> ]
> 
> ```

I acheived above same way as link import workaround - Import it to top flow and than copy with copy/paste inside.

Strange here that I can't import just inside Subflow2 , because result is same and no "infinite repeating" happen, so I think it checks not nodes it going to insert, but original nodes user pasted.

---

<div class="post-metadata">

**Author:** ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)\
**Post date:** [5 June 2024 19:11 UTC](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506/20 "2024-06-05T19:11:04Z")

</div>

For the loop part, I don't know how to explain it to you - maybe @knolleary or @dceejay if he's available.

When you import a subflow node into a subflow, the import will fail because the active workspace (the tab) is your subflow.

[Next page](https://discourse.nodered.org/t/link-out-link-in-in-subflows-after-copy/88506.md?page=2)
