Skip to content

Conversation

@fpapado
Copy link

@fpapado fpapado commented Jul 24, 2025

Motivation

This PR fixes a "RangeError: Maximum call stack size exceeded" error from transform's cache.ts invalidateIfChanged, when import cycles are present. This shows up in @wyw-in-js/transform@0.7.0, and for example can be shown in linaria's transformer tests failing (you would have to link against 0.7.0 and run the tests to validate that).

This was also mentioned in a PR comment, and we ran into that same issue while investigating an upgrade of linaria's transformers to 0.7.0, linking against our app.

Summary

We carry forward a visitedFiles Set in the recursion step, and use it to break cycles. Please let me know if I have missed something, or if you prefer some other idiom for handling cycles.

Test plan

I added a test that demonstrates the failing scenario without the changes. If you edit the recursion step to provide an empty new Set() as the parameter (or undefined), it should be equivalent to the previous version, and the tests should fail. All files are ultimately still visited (and the tests verify that), we just avoid the cycle in a given invalidation call chain.

CleanShot 2025-07-24 at 12 13 29@2x

@changeset-bot
Copy link

changeset-bot bot commented Jul 24, 2025

🦋 Changeset detected

Latest commit: a7a7b3a

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@fpapado fpapado marked this pull request as ready for review July 24, 2025 09:15
@fpapado fpapado changed the title Fix: Avoid cycles in transform cache invalidateIfChanged method fix(transform): avoid cycles in transform cache invalidateIfChanged method Jul 24, 2025
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