Weird behavior when using the saveAsNewWorkflow function

Describe the issue/error/question

For background, we are rendering n8n in a window as an iframe.

So, I wrote some logic to automatically create a new workflow or redirect them to an existing one if it matches a specific key in the query params.

What is the error message (if any)?

Not an error message, but the behavior is weird, if it’s going to create a new workflow, I made it create it using the saveAsNewWorkflow function, then I call saveCurrentWorkflow using that new name from the query params, then dispatch(settings/fetchPromptsData).

However, this sometimes cause the final redirect to have a start node with node + button, meaning I’m not able to add any new nodes. This is only fixed if I close the iframe and open it again so that instead of creating it redirects to that workflow, then this works fine.

Here’s a picture of the logic.

Please share the workflow

(Select the nodes and use the keyboard shortcuts CMD+C/CTRL+C and CMD+V/CTRL+V to copy and paste the workflow respectively)

Share the output returned by the last node

Information on your n8n setup

  • n8n version: - 0.184.0
  • Database you’re using (default: SQLite): - default
  • Running n8n with the execution process [own(default), main]: - default
  • Running n8n via [Docker, npm, n8n.cloud, desktop app]: - npm

Hi @Marfuen, perhaps it’s easier to create your workflow via the REST API, then simply navigate to the respective URL in your iframe? This way the workflow will only be rendered once, hopefully without any trouble.

Hi @Marfuen,
I’ve checked the code and here are some observations I’ve made.

  1. saveCurrentWorkflow will execute saveAsNewWorkflow if this.$route.params.name does not exist. Does this mean your implementation calls saveAsNewWorkflow twice?

  1. saveCurrentWorkflow will redirect by default which you should hit, right?

  1. if you call saveAsNewWorkflow with redirect: true (default) it will use the param action: ‘workflowSave’

Questions

  1. Did you try only using saveAsNewWorkflow without saveCurrentWorkflow, like DuplicateWorkflowDialog.vue is doing it?

  2. Where are you executing redirectToWorkflow?

@marcus Thanks for your tips, I will try this out.

I will take a look.

@marcus It seems only using saveCurrentWorkflow works, thanks!

1 Like