Skip to content

fix(typegen): avoid possible infinite recursion error #630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 6, 2025

Conversation

avallete
Copy link
Member

@avallete avallete commented Aug 4, 2025

Related:
supabase/supabase-js#1354
supabase/supabase-js#1372
supabase/supabase-js#808

@avallete avallete requested a review from soedirgo August 4, 2025 12:35
@avallete avallete marked this pull request as draft August 4, 2025 13:29
@avallete avallete force-pushed the fix/limit-types-depth-recursion branch from 04c89fb to 721b142 Compare August 5, 2025 10:59
Copy link
Member Author

@avallete avallete left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After attempting many things:

(based on: https://www.esveo.com/en/blog/how-to-workaround-the-max-recursion-depth-in-typescript/)

  • Tail recursion
  • Batches handling
  • Reseting counter to 0

None of them really improved the issue, I've figured out that this error is mainly a regression due to the newly introduced Omit. It'll still happen for complex queries though.

The only "optimization" that had a bit of value were hardcoding some "batches" to reduce the recursion inference. It didn't allowed much deeper recursions though, only improved a bit the inference speed (~10%). Might introduce this in future changes, keeping this one focused on reversing the regression and adding tests cases for it.

@@ -40,8 +40,8 @@
"test": "run-s format:check test:types db:clean db:run test:run db:clean && node test/smoke.cjs && node test/smoke.mjs",
"test:run": "jest --runInBand --coverage",
"test:update": "run-s db:clean db:run db:generate-test-types && jest --runInBand --updateSnapshot && run-s db:clean",
"test:types": "run-s build && tsd --files 'test/**/*.test-d.ts'",
"test:types:watch": "run-s build && tsd --files 'test/**/*.test-d.ts' --watch",
"test:types": "run-s build && tsd --files 'test/**/*.test*.ts'",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that we have types and tests merged together, we want to check for all tests files that the types assertions passes.

package.json Outdated
"test:types": "run-s build && tsd --files 'test/**/*.test-d.ts'",
"test:types:watch": "run-s build && tsd --files 'test/**/*.test-d.ts' --watch",
"test:types": "run-s build && tsd --files 'test/**/*.test*.ts'",
"test:types:watch": "chokidar 'src/select-query-parser/**/*.ts' 'test/**/*.ts' -c 'npm run test:types'",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous watcher weren't working. Use chodikar for better DX to check the types errors.

@avallete avallete marked this pull request as ready for review August 5, 2025 11:06
- Add a fixed max depth to recursive types allowing Typescript to not raise
possible infinite recursion error too early.
- Add test to ensure that the provided fix remove this error from a recursive embeding

Related:
supabase/supabase-js#1354
supabase/supabase-js#1372
supabase/supabase-js#808
Fixes regression introduced in #627
While fixing the invalid intersection for conflicting keys case
the Omit did lead to a huge increase in the recursive type complexity
Removing it bring back the corner case, but allow much more longer queries.

A test is now in place to ensure minimal coverage over the query complexities
we can handle before reaching infinite recursion errors.
@avallete avallete force-pushed the fix/limit-types-depth-recursion branch from 721b142 to 876014e Compare August 5, 2025 11:09
@avallete avallete merged commit d7d6f8b into master Aug 6, 2025
3 checks passed
Copy link

github-actions bot commented Aug 6, 2025

🎉 This PR is included in version 1.21.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants