Skip to content

Invalidate compiled handler after route additions - #1909

Open
puneetdixit200 wants to merge 1 commit into
elysiajs:mainfrom
puneetdixit200:fix-async-route-compile-invalidation
Open

Invalidate compiled handler after route additions#1909
puneetdixit200 wants to merge 1 commit into
elysiajs:mainfrom
puneetdixit200:fix-async-route-compile-invalidation

Conversation

@puneetdixit200

@puneetdixit200 puneetdixit200 commented Jun 4, 2026

Copy link
Copy Markdown

Fixes #1907.

Summary:

  • clear the memoized compiled handler when routes are added
  • add a regression test for a route registered after an async plugin has already caused precompilation

Tests:

  • red check before the fix: focused regression returned NOT_FOUND
  • BUN_INSTALL_CACHE_DIR=/tmp/elysia-1907-bun-cache bun test test/aot/analysis.test.ts -t "handles route added after async plugin compilation"
  • BUN_INSTALL_CACHE_DIR=/tmp/elysia-1907-bun-cache bun test test/aot/analysis.test.ts
  • BUN_INSTALL_CACHE_DIR=/tmp/elysia-1907-bun-cache bun test test/aot
  • BUN_INSTALL_CACHE_DIR=/tmp/elysia-1907-bun-cache bun test test/core/elysia.test.ts
  • BUN_INSTALL_CACHE_DIR=/tmp/elysia-1907-bun-cache bun run test:types
  • BUN_INSTALL_CACHE_DIR=/tmp/elysia-1907-bun-cache bunx prettier --check src/index.ts test/aot/analysis.test.ts
  • git diff --check

Also checked:

  • BUN_INSTALL_CACHE_DIR=/tmp/elysia-1907-bun-cache bun run test:functionality currently fails on test/sucrose/integration.test.ts > Allows process to finish and test/response/stream.test.ts > stop stream on canceled request; both failures reproduce on clean upstream HEAD (56310be) in a separate worktree, so I did not treat them as part of this change.

AI assistance was used while drafting this patch; I reviewed the diff and verified the results above.

Summary by CodeRabbit

  • Bug Fixes

    • Routes added after precompilation now function correctly and are properly handled by the router.
  • Tests

    • Added test coverage for route registration following precompilation in async plugin scenarios.

@coderabbitai

coderabbitai Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 830e3546-d21c-4f7b-83cf-eb6c11611a7c

📥 Commits

Reviewing files that changed from the base of the PR and between 56310be and 8093109.

📒 Files selected for processing (2)
  • src/index.ts
  • test/aot/analysis.test.ts

Walkthrough

This PR fixes a critical AoT precompile bug where routes registered after async plugins fail to be found. The fix adds a invalidateCompilation() helper that clears cached handlers, integrates it into route registration, and verifies late-bound routes now work correctly with test coverage.

Changes

Route registration with compilation refresh

Layer / File(s) Summary
Compilation invalidation mechanism and test
src/index.ts, test/aot/analysis.test.ts
Router type imported; invalidateCompilation() helper method deletes cached fetch and resets _handle to undefined; method called after dynamic and static route registration to force recompilation; test verifies routes added after async plugin compilation with precompile: true are successfully handled.
Async guard handling formatting adjustments
src/index.ts
hasStandaloneSchema condition and localHook.error merge ternary reformatted across multiple lines for readability; no functional changes.

🎯 2 (Simple) | ⏱️ ~12 minutes


The cached handlers crumble and fall~♡
When new routes arrive after the call,
But now we'll invalidate them all—
Fresh compilation, no NOT_FOUND stall~✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Invalidate compiled handler after route additions' clearly summarizes the main change: clearing/invalidating memoized compilation artifacts when routes are added.
Linked Issues check ✅ Passed The PR successfully addresses issue #1907 by implementing route compilation invalidation logic that prevents AoT-compiled handlers from missing dynamically added routes.
Out of Scope Changes check ✅ Passed All changes (helper function, route registration hooks, formatting adjustments, and regression test) are directly scoped to fixing the AoT route compilation issue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

src/index.ts

Oops! Something went wrong! :(

ESLint: 9.39.4

Error: ESLint configuration in --config » plugin:sonarjs/recommended is invalid:

  • Unexpected top-level property "name".

Referenced from: /.eslintrc.json
at ConfigValidator.validateConfigSchema (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2277:19)
at ConfigArrayFactory._normalizeConfigData (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3123:19)
at ConfigArrayFactory._loadExtendedPluginConfig (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3346:25)
at ConfigArrayFactory._loadExtends (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3259:29)
at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3199:25)
at _normalizeObjectConfigDataBody.next (<anonym

... [truncated 291 characters] ...

/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2952:16)
at createCLIConfigArray (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3768:35)
(node:2) ESLintRCWarning: You are using an eslintrc configuration file, which is deprecated and support will be removed in v10.0.0. Please migrate to an eslint.config.js file. See https://eslint.org/docs/latest/use/configure/migration-guide for details. An eslintrc configuration file is used because you have the ESLINT_USE_FLAT_CONFIG environment variable set to false. If you want to use an eslint.config.js file, remove the environment variable. If you want to find the location of the eslintrc configuration file, use the --debug flag.
(Use node --trace-warnings ... to show where the warning was created)

test/aot/analysis.test.ts

Oops! Something went wrong! :(

ESLint: 9.39.4

Error: ESLint configuration in --config » plugin:sonarjs/recommended is invalid:

  • Unexpected top-level property "name".

Referenced from: /.eslintrc.json
at ConfigValidator.validateConfigSchema (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2277:19)
at ConfigArrayFactory._normalizeConfigData (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3123:19)
at ConfigArrayFactory._loadExtendedPluginConfig (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3346:25)
at ConfigArrayFactory._loadExtends (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3259:29)
at ConfigArrayFactory._normalizeObjectConfigDataBody (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3199:25)
at _normalizeObjectConfigDataBody.next (<anonym

... [truncated 291 characters] ...

/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2952:16)
at createCLIConfigArray (/node_modules/.pnpm/@eslint+eslintrc@3.3.5/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3768:35)
(node:2) ESLintRCWarning: You are using an eslintrc configuration file, which is deprecated and support will be removed in v10.0.0. Please migrate to an eslint.config.js file. See https://eslint.org/docs/latest/use/configure/migration-guide for details. An eslintrc configuration file is used because you have the ESLINT_USE_FLAT_CONFIG environment variable set to false. If you want to use an eslint.config.js file, remove the environment variable. If you want to find the location of the eslintrc configuration file, use the --debug flag.
(Use node --trace-warnings ... to show where the warning was created)


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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.

AoT breaks plugin added after await

1 participant