[PR #13165] Solve circular dependency issue between workflow/constants.ts file and default.ts file #27854

Closed
opened 2026-02-21 20:42:19 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/13165

State: closed
Merged: Yes


Summary

there is a lurking bug in the web code caused by a circular dependency issue.

the problem is that web/app/components/workflow/nodes/if-else/default.ts (and other default files) imports from web/app/components/workflow/constants.ts, and the latter imports from the former values to populate the NODES_EXTRA_DATA object.

if default.ts file is imported first, then nodeDefault will be defined, which means when constants.ts is imported, the code that populates the NODES_EXTRA_DATA object will be able to read values from nodeDefault because it is defined.

when constants.ts is imported before default.ts, the former will try to import from the latter, and this time an cannot read property of undefined error message will be thrown because nodeDefault isn't defined yet.

right now the order of resolution runs default.ts, which causes no problems, but it might change when adding new dependencies, which is what makes this PR a prerequisite to #13166, because importing PromptEditor in Form.tsx changed the order of resolution in a way that broke the app with the error message: cannot read property of undefined.

Checklist

Important

Please review the checklist below before submitting your pull request.

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/13165 **State:** closed **Merged:** Yes --- # Summary there is a lurking bug in the web code caused by a circular dependency issue. the problem is that `web/app/components/workflow/nodes/if-else/default.ts` (and other default files) imports from `web/app/components/workflow/constants.ts`, and the latter imports from the former values to populate the `NODES_EXTRA_DATA` object. if `default.ts` file is imported first, then `nodeDefault` will be defined, which means when `constants.ts` is imported, the code that populates the `NODES_EXTRA_DATA` object will be able to read values from `nodeDefault` because it is defined. when `constants.ts` is imported before `default.ts`, the former will try to import from the latter, and this time an `cannot read property of undefined` error message will be thrown because `nodeDefault` isn't defined yet. right now the order of resolution runs `default.ts`, which causes no problems, but it might change when adding new dependencies, which is what makes this PR a prerequisite to #13166, because importing `PromptEditor` in `Form.tsx` changed the order of resolution in a way that broke the app with the error message: `cannot read property of undefined`. # Checklist > [!IMPORTANT] > Please review the checklist below before submitting your pull request. - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!) - [x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change. - [x] I've updated the documentation accordingly. - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:42:19 -05:00
yindo closed this issue 2026-02-21 20:42:20 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#27854