-
-
Notifications
You must be signed in to change notification settings - Fork 365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Page variable is overwritten when page.js.twig is included in a dynamically loaded component #1104
Comments
We could also consider a system that automatically scopes variables in dynamically loaded components to those specific components, a la Angular and other JS frameworks. Now that I think about it, blindly doing a deep merge doesn't make that much more sense than blindly doing an overwrite. |
IMO the |
I agree, but the way we have it designed now it is too easy to accidentally overwrite it by including |
Ugh. I spotted a type. I meant it should be treated as immutable in JS. |
Ah ok. Well in that case we definitely should be using separate variables for different components, then. |
page.js.twig
currently sets thepage
Javascript variable to import page-specific variables from the server into the client JS environment. However it looks like in some cases we load this partial both in the base page as well as dynamic components such as modal forms.This means that the original value set in the base page gets completely overwritten when the modal form is loaded.
The simplest solution seems to be merging, rather than setting, the page variable by changing
page.js.twig
:This doesn't completely guarantee that nested values in
page
won't be overwritten, of course. But it at least provides a mechanism for easily setting additional client-side variables while keeping them scoped under the top-levelpage
object.The text was updated successfully, but these errors were encountered: