SFDigitalServices / formio-sfds

The form.io theme for sf.gov
https://formio-sfds.herokuapp.com/
MIT License
15 stars 2 forks source link

Force redraw forms on language change #155

Closed shawnbot closed 3 years ago

shawnbot commented 3 years ago

Over in #154 I detailed why I think Filipino translations aren't working on some forms. This is a fix, which you can test by repeatedly reloading this preview URL and comparing how it (for me, at least) always displays the Filipino translations. (The sf.gov URL does not.)

The problem appears to be that the form isn't explicitly redrawn after translations are loaded. Now, I'm not 100% sure about why this works, because our patched Formio.createForm() implementation fetches the Phrase translations before patching the form model object, which should always force a redraw.

My guess is that translations are being loaded, the model is being patched, then the language attribute is being changed by Google Translate, which triggers our updateLanguage() function, and this patch just adds another redraw() call that forces the form to apply the new translations. But the failure state is hard to simulate because it's based on a very specific order of operations. The only proof I have that it works is by reloading the preview page over and over again in a real browser. 😬

vercel[bot] commented 3 years ago

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/sfds/formio-sfds/qntpt53fq
✅ Preview: https://formio-sfds-git-force-lang-redraw.sfds.vercel.app

github-actions[bot] commented 3 years ago

Size Change: +183 B (0%)

Total Size: 92.1 kB

Filename Size Change
dist/formio-sfds.standalone.js 68.3 kB +183 B (0%)
ℹ️ View Unchanged | Filename | Size | Change | | |:--- |:---:|:---:|:---:| | `dist/common.css` | 332 B | 0 B | | | `dist/examples.js` | 3.51 kB | 0 B | | | `dist/examples/example.js` | 508 B | 0 B | | | `dist/formio-sfds.css` | 14 kB | 0 B | | | `dist/portal.js` | 5.36 kB | 0 B | |

compressed-size-action