Briskine / briskine

Write faster with templates and keyboard shortcuts.
https://www.briskine.com/
GNU General Public License v3.0
108 stars 23 forks source link

Updates to templates on server don't always sync to client extension #536

Closed e-t-l closed 4 months ago

e-t-l commented 5 months ago

Description

Steps to reproduce:

  1. Open a mail client that has the Briskine extension installed.
  2. Edit and save an existing template from the Briskine Dashboard.
  3. Refresh the mail client webpage and click the "sync templates now button" on the extension's flyout menu.
  4. Insert the template into an email. At this point, it might insert the correct, up-to-date version. If so, continue...
  5. On the Briskine Dashboard, make more edits to the template and save it.
  6. Again, refresh the mail client webpage and click the "sync templates now button" on the extension flyout. You can even try refreshing the Briskine Dashboard tab and/or fully restarting your web browser.
  7. Insert the template into an email. The result should be an older version of your template, not reflecting the most recent changes you had saved.
  8. (If it is still inserting the correct, most-recent version of the template, try repeating steps 5-7 a few more times.)
  9. (If it still isn't reproducing the bug, try editing a variable syntax error into the template, saving it, then inserting it. Then make another edit that fixes the syntax error, save it, and insert it.*)

*I have a suspicion, although unlikely to be correct, that there is some issue with syncing the templates that occurs only when the handlebarjs syntax in the template is not valid. This may just be because the scenario where I am frequently editing and updating templates is when I'm trying to fix syntax errors, so when the bug occurs for me, it frequently leaves me stuck with a version of my template that produces a syntax error.

... For the record, the template that I originally tried was: Hi {{#if to.0.first_name}}{{capitalizeAll to.0.first_name}}{{#if to.1.first_name}} but that produced the syntax error:

Parse error on line 3:
... cc.0.first_name}}{{capitalizeAll c
-----------------------^
Expecting 'ID', 'STRING', 'NUMBER', 'BOOLEAN', 'UNDEFINED', 'NULL', 'DATA', got 'INVALID'

When I updated the template to just Hi {{#if to.0.first_name}}{{to.0.first_name}}{{#if to.1.first_name}} and saved it, that's when I encountered the bug. Even after refreshing and force-syncing my templates multiple times, it still produces the above error message whenever I try to insert that template.

P.S. Do you know why capitalizeAll doesn't seem to work when used within an #if block? It works fine outside of one.

ghinda commented 4 months ago

Thank you for the detailed report. Unfortunately, I was not able to reproduce the issue. I'll try different scenarios to see if I can reproduce it. If you could isolate the issue further, that would really help.

There shouldn't be any differences when syncing templates with or without syntax errors. The sync itself (or the dashboard for that matter) does not parse or care about the Handlebars syntax. The way it works is:

I'm guessing your issue is probably related to this sync time (e.g., updated a template, closed the dashboard tab immediately).

About capitalizeAll: it should work in #if blocks just as well. I've just tested {{#if to.first_name}}{{capitalizeAll to.first_name}}{{/if}} and it seems to be ok.

e-t-l commented 4 months ago

Hmm I left the dashboard tab open and waited more than several seconds after saving the template to re-syncing templates in the extension, so I don't think it's that...

Today it has now successfully synced all the template changes from yesterday, so the issue is gone for now. Also, I noticed a different template had {{#if to.first_name}}{{capitalizeAll to.first_name}}{{/if}} working properly, so I deleted the identical line in the template that was throwing the error and replaced it with the one I copied from the good template. Even though both lines looked truly identical and I couldn't spot any typos, it now parses correctly. No idea what's going on there. I'll close this issue for now and reopen it if I can replicate the problem more reliably or figure out anything further about it.