Skip to content
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

Cannot access templateVars.options in templates #5730

Closed
hecktarzuli opened this issue May 14, 2019 · 7 comments · Fixed by #5776
Closed

Cannot access templateVars.options in templates #5730

hecktarzuli opened this issue May 14, 2019 · 7 comments · Fixed by #5776

Comments

@hecktarzuli
Copy link
Contributor

hecktarzuli commented May 14, 2019

Version

v2.7.0

Reproduction link

https://codesandbox.io/s/946pw7j9k4

Steps to reproduce

a) create a module that injects a plugin
b) have plugin use lodash syntax to fill in vars from templateVars
c) notice that even though templateVars.options exists, it's { } in the written template

The problems seems to be with https://github.com/nuxt/nuxt.js/blob/dev/packages/builder/src/builder.js#L515 which merges options with the template, even if options isn't passed.

What is expected ?

My assumption is that anything you see in templateVars should be accessible in a template!

What is actually happening?

options prop is being reset

Additional comments?

a) could maybe see if options is being passed to the template, then let it override it (which still is kind of crummy)
b) could move either options or templateVars.options into a new prop in templateVars so it's always accessible.

This bug report is available on Nuxt community (#c9215)
@ghost ghost added the cmty:bug-report label May 14, 2019
@Atinux
Copy link
Member

Atinux commented May 21, 2019

Actually, I am wondering why do we have templateVars.options initialized with Nuxt options.

An idea @clarkdo?

@clarkdo
Copy link
Member

clarkdo commented May 21, 2019

@Atinux I'm not sure the initial situation, but I suppose that user may need sth like options.dev or other options to do some special process in templates.

@hecktarzuli Thanks for the reporting, I'll propose a fix.

@hecktarzuli
Copy link
Contributor Author

hecktarzuli commented May 21, 2019

For more context @Atinux , in our case, our system generates 6 websites, and so we have an advanced config system and need config data in our plugins so we can build them using the right settings.

We are using this for now until this patch is in place.
image

@clarkdo
Copy link
Member

clarkdo commented May 23, 2019

@hecktarzuli As @pi0 pointed, merge options into template may be a breaking change, so I added nuxtOptions as nuxt options in template and keep options as template.options, do this make sense for you ?

@hecktarzuli
Copy link
Contributor Author

hecktarzuli commented May 23, 2019

Sounds good to me. That's probably the safest course of action.
I am a little confused though, it seems via this comment (and your agree) that this patch is only for me and will be undocumented or something?

#5792 (comment)

If it's going to be undocumented, then what's the point of the merge if nobody knows about it?

@clarkdo
Copy link
Member

clarkdo commented May 23, 2019

@hecktarzuli There are some other libraries/modules are using tempalte.options like serializing template.options, if we merge options, the serialized object will be huge and contain all nuxt.options.

@pi0
Copy link
Member

pi0 commented May 23, 2019

@hecktarzuli Modules that really need can leverage it. Indeed we can document it in the future. Not documenting for now is more because to not encourage using it over explicit templateFile.options. And also due the fact that some internal config refactors may impact usage.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants