Skip to content

Finish render hooks for cache hits and hook errors - #447

Merged
jaredwray merged 2 commits into
mainfrom
cursor/render-hooks-6b6a
Oct 26, 2026
Merged

jaredwray merged 2 commits into
mainfrom
cursor/render-hooks-6b6a

Conversation

@jaredwray

Copy link
Copy Markdown
Owner

Please check if the PR fulfills these requirements

  • Followed the Contributing and Code of Conduct guidelines.
  • Tests for the changes have been added (for bug fixes/features) with 100% code coverage.

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

Bug fix for the beforeRender, afterRender, beforeRenderSync, and afterRenderSync hooks.

Summary

Those four hooks already ran inside render and renderSync. This change makes the documented contract hold:

  • Hookified constructor options, including throwOnHookError, are passed through to the base class.
  • The async and sync caches store the template engine output. afterRender / afterRenderSync run on every call, including cache hits, so a suffix or other non-idempotent change is applied once per call.
  • With throwOnHookError: true, a hook failure rejects render and throws from renderSync. The default still emits error and continues, including when no error listener is attached.
  • filePathOutput on the hook context is the path that gets written, so a before-hook can redirect output.
  • renderSync continues to skip async hook handlers.

Test plan

  • pnpm test (Biome plus Vitest coverage)
  • Hook tests cover source and data edits, hook order, cache hits, output paths, and throwOnHookError for both async and sync renders
Open in Web Open in Cursor 

beforeRender, afterRender, and the sync pair already run in the pipeline.
Pass Hookified options through the constructor, cache engine output before
after-hooks so a hit does not apply them twice, and reject the render when
throwOnHookError is set.

Co-authored-by: Jared Wray <me@jaredwray.com>
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 26, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-26T21:25:34.721445Z c106a1e PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Co-authored-by: Jared Wray <me@jaredwray.com>
@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (e0a1688) to head (3c9f5d9).
⚠️ Report is 32 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main      #447   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            9         9           
  Lines          406       438   +32     
  Branches        94       102    +8     
=========================================
+ Hits           406       438   +32     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c106a1e597

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/ecto.ts
Comment on lines +1097 to +1099
} finally {
if (swallowEmpty) {
this.off(EctoEvents.error, ignoreHookError);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Keep error suppression active for overlapping hook invocations

When two renders overlap on the same Ecto instance without an error listener, the first invocation installs the temporary listener and the second sees it and skips installing its own. If the first finishes while the second is still awaiting an async hook, this cleanup removes their only listener. A subsequent failure in the second hook then escapes through the unhandled error event, rejecting that render despite throwOnHookError being false and the documented continue-rendering behavior. Track active invocations or otherwise ensure that each pending invocation retains error suppression until it finishes.

Useful? React with 👍 / 👎.

@jaredwray
jaredwray merged commit d46f616 into main Oct 26, 2026
13 checks passed
@jaredwray
jaredwray deleted the cursor/render-hooks-6b6a branch October 26, 2026 21:37
@jaredwray jaredwray mentioned this pull request Oct 26, 2026
6 tasks done
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.

2 participants