Skip to content

Fix templater execution timing for code block buttons#274

Merged
shabegom merged 3 commits into
mainfrom
fix/templater-execution-timing
Aug 5, 2025
Merged

Fix templater execution timing for code block buttons#274
shabegom merged 3 commits into
mainfrom
fix/templater-execution-timing

Conversation

@shabegom
Copy link
Copy Markdown
Owner

@shabegom shabegom commented Aug 5, 2025

Problem

Fixes a bug reported on Discord where templater scripts inside append text buttons with timestamps fail to update with the actual time. The templater scripts were being executed at button creation/parse time instead of at button click time, causing time-sensitive commands like tp.date.now() to be "frozen" at the time the button was created.

Root Cause

There was an inconsistency in when templater scripts are processed:

  1. Code block buttons: Templater processing happened during parse time (when the button is rendered) in src/index.ts, not when clicked ❌
  2. Inline buttons: Templater processing happened during click time in the button handlers ✅

Solution

  1. Removed parse-time templater processing from src/index.ts (lines 82-92)
  2. Updated click-time templater processing in src/button.ts to work for all buttons, not just inline ones
  3. Updated error messages to be generic instead of "inline button" specific
  4. Removed unused templater import from src/index.ts

Changes

  • src/index.ts: Removed parse-time templater processing and unused import
  • src/button.ts: Removed inline-only restriction for templater processing

Testing

  • ✅ Project builds successfully with no TypeScript errors
  • ✅ No new linting errors introduced
  • ✅ Templater commands now execute at click time for all button types

Impact

This ensures that templater scripts like <% tp.date.now("HH:mm:ss") %> will execute fresh on each button click, providing the current time instead of the time when the button was created.

Resolves Discord bug report about templater scripts not updating on button click.

- Remove parse-time templater processing from src/index.ts
- Update click-time templater processing in src/button.ts to work for all buttons, not just inline
- This ensures templater scripts like tp.date.now() execute at click time instead of button creation time
- Fixes issue where time-sensitive templater commands would be frozen at button creation

Resolves Discord bug report about templater scripts not updating on button click.
@netlify
Copy link
Copy Markdown

netlify Bot commented Aug 5, 2025

Deploy Preview for buttons-docs canceled.

Name Link
🔨 Latest commit dd976ff
🔍 Latest deploy log https://app.netlify.com/projects/buttons-docs/deploys/68923daf91bf17000888b7ed

- Remove inline-only restriction from livePreview.ts templater processing
- Update error messages to be consistent with button.ts changes
- This ensures templater commands work in both editing and reading modes

This completes the fix for the templater execution timing issue.
@cursor
Copy link
Copy Markdown

cursor Bot commented Aug 5, 2025

🚨 Bugbot Trial Expired

Your Bugbot trial has expired. Please purchase a license in the Cursor dashboard to continue using Bugbot.

- Create processedArgs copy instead of mutating original args object
- This prevents templater results from being cached/stuck between clicks
- Update all button handlers to use processedArgs for action-related operations
- Fixes the core issue where templater commands like tp.date.now() would
  get processed once and then reuse the same result on subsequent clicks

The problem was that args.action was being permanently modified from
'<% tp.date.now() %>' to '14:30:15', so subsequent clicks would use
the static processed result instead of re-executing the templater command.
@cursor
Copy link
Copy Markdown

cursor Bot commented Aug 5, 2025

🚨 Bugbot Trial Expired

Your Bugbot trial has expired. Please purchase a license in the Cursor dashboard to continue using Bugbot.

@shabegom shabegom merged commit 2e6506e into main Aug 5, 2025
5 checks passed
@shabegom shabegom deleted the fix/templater-execution-timing branch August 5, 2025 17:28
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