Open trainiac opened 7 years ago
Yup that's true. Hot module reloading won't update the translation tags content.
However, for me in any case, it's never been an issue since such a change most likely implies a change in the translations files so you have to compile translations again, relaunch the dev server etc.
Also I'm curious about how you can use this.$slots.default
since no slot is ever used in the component template? I'm not able to access this.$slots
in the current state of the component without trigerring an error.
Hmm maybe it's because I'm using a webpack vue-loader build process. I assumed by default every custom component that gets passed content implicitly has $slot.default, but perhaps it's due to my build system.
With the changes I made above, I have access to this.$slots.default.
There are a few examples of rendering components using $slots where it's not defined in templates. https://vuejs.org/v2/guide/render-function.html
Have you tried only accessing $slots in the render function? Maybe in created $slots has not been created yet. But it is strange that it worked for me.
When using hot module reloading with webpack, the text doesn't update when making changes. This is because the
msgid
property in thetranslate
component is decided when the componentcreated
event.I tried moving the logic in the
created
function into thetranslation
computed property but that doesn't update because$options._renderChildren
(which we should consider changing to$slots.default
in order to not access a private property) is not a reactive property so nothing would trigger the computed property to update. Even $slots is not a reactive property, so computed property is not the solution.It seems like the only way this works is if moving the logic into another part of the component life cycle. This probably has some performance implications so I wanted to propose something and I'll submit a PR if it seems appropriate.
So the changes are:
msgid
reactivebeforeUpdate
function that updates themsgid
before rendering.develop
that if set totrue
would extend the translate component configuration with thebeforeUpdate
. This way the extra function call won't happen on each rerender.