Skip to content

Return after circular dependency callback in topologicalSort - #20739

Open
ragib-mrb wants to merge 1 commit into
tailwindlabs:mainfrom
ragib-mrb:fix/topological-sort-cycle-return
Open

ragib-mrb wants to merge 1 commit into
tailwindlabs:mainfrom
ragib-mrb:fix/topological-sort-cycle-return

Conversation

@ragib-mrb

Copy link
Copy Markdown
Contributor

Problem

In packages/tailwindcss/src/utils/topological-sort.ts, when a circular dependency is detected (wip.has(node)), visit invokes options.onCircularDependency?.(path, node) without returning:

if (wip.has(node)) options.onCircularDependency?.(path, node)

If onCircularDependency does not throw (for example, when collecting cycles or logging a warning), visit continues traversing the cycle and overflows the call stack (RangeError: Maximum call stack size exceeded).

Fix

  • Return immediately after calling options.onCircularDependency?.(path, node) when wip.has(node) is true.
  • Add unit tests in packages/tailwindcss/src/utils/topological-sort.test.ts.

Verification

  • .\node_modules\.bin\vitest.cmd run packages/tailwindcss/src/utils/topological-sort.test.ts (2/2 passing; fails with RangeError: Maximum call stack size exceeded before fix)
  • .\node_modules\.bin\prettier.cmd --check packages/tailwindcss/src/utils/topological-sort.ts packages/tailwindcss/src/utils/topological-sort.test.ts (passing)

@ragib-mrb
ragib-mrb requested a review from a team as a code owner November 21, 2026 10:34
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.

1 participant