-
-
Notifications
You must be signed in to change notification settings - Fork 5k
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
1.0.0-alpha Breaking changes #754
Comments
@John0x I think you were too fast in adopting. The website and changelog still does not exist. As far as I can see the most important change is removing |
I'm getting this too:
Assuming that's a breaking change and not a bug? |
Sigh |
+1 |
What's surprising to me is that the new package was pushed to NPM, but no release was made on Github. It's entirely possible this release was a mistake and was intended for internal use. |
New release runInNewContextMost of breaking changes are because of new vue SSR performance improvements. Each render request is by default executing in the same process context as server while this gives huge improvements it needs additional steps in your project code. learn more Store & Sub Modules state should return a functionAs of global context, just like data function for components which returns a function instead of data itself we need to make this change for stores as well.
const createStore = () => new Vuex.store({
// Store options
}
export state = () => {
// initial state data
} Plugins should export a function if want to mutate global stateIf your plugins are changing global state, such as store and API tokens you should export a function which sets it for each request.
(for programmatically usage, with express or ..)UPDATE: This will revert with next alpha release (alpha3) and change wont be needed any moreIf you are using nuxt API, now you should await on nuxt constructor to ensure that are modules are initialized. new Nuxt(options).then(nuxt => {
nuxt.build()
.then(() => {
// You can use nuxt.render(req, res) or nuxt.renderRoute(route, context)
})
.catch((e) => {
// An error happened during the build
})
}) |
How would the vue-apollo example be updated with the new Note that I've seen the i18n example, but the vue-apollo integration needs to inject apolloProvider into the Vue instance. I don't see which line in the i18n example does this and I[m not familiar with that plugin. Thanks. |
@pi0 How to get store instance now? In the previous version is
|
I'd like to know this too. I figured out the answer to my own question--turns out Thanks. |
Store instance is available in vue components instance as |
Ok, i has been found it, i use store instance in plugins, example https://nuxtjs.org/examples/i18n/ Thanks. |
If I understand correctly, the Nuxt constructor now returns a promise? |
@lewebsimple Thanks for your tip. With |
@pi0 do you know how the changes on |
@dohomi Sure. Will work on that soon ;) |
@pi0 how do you import in plugins now? Ie I normally import axios through an instance i created as a plugin. For example, Now that '~' is no longer available and the plugin file returns a function, are the plugins registered somewhere globally? |
@pi0 is there a more expansive breaking changes document? |
@uptownhr For your first question, access plugins instance is a little more tricky, as SSR context is shared across request. You may use axios module for easier usage or looking into it's implementation to get idea how we could access context from inside components. (There is also another workaround using
It should not happen!! If possible please prepare a glitch test to reproduce problem and opening an issue for that. |
hi @pi0 modules is new to me and I need to look at it more. But it looks like it will not resolve the issue I am having. As I'd like to get access to the same axios instance from all parts of the app. Like store, plugins, middleware or even my own personal library. Last night i wrote a quick workaround but let me know if I'm thinking about this incorrectly and if there is a better approach. Here is my plugins/axios.js
This exports the default function to retrieve the context and exports another axios. Now I can import |
Consider axios instance is created in global context! So is being shared across requests in server side. This is a wrong and insecure approach. Actually your workaround is working, until we need adding some request specific options like tokens from cookies. Take a look at axios/plugin.js#L87 : export default ({app}) => {
// Create new axios instance
const axios = Axios.create({
baseURL: API_URL + (process.env.API_PREFIX || '/api')
})
// Setup instance interceptors
axios.interceptors.request.use(withCredentials);
axios.interceptors.response.use(undefined, handleError);
// Make accessible using {this,$nuxt}.$root.$options.$axios
app.$axios = axios
// setToken helper
axios.setToken = setToken.bind(axios)
} |
@pi0 Why are only states supposed to return a function and not actions and mutations? And how can I use axios inside a store now? |
Know any one a solution for that? |
@John0x Sorry for delay answering. Give us a little more time we are actively working on new changes and their documentation, Also will update axios and auth store modules soon for reference :) |
@pi0 I want encapsulate my api logic in classes, but for that i need the jwt token from my store. I have the same problem with the router, I want use it in my store modules, but I dont know how to get him. A solution is to pass it to the action as parameter, but I found this to hacky. |
@pi0 I also tried to migrate my project to version 1.0 but I failed so far. I am using Like others here did as well, I imported the client instance from the My apollo.js plugin file looks like this:
From what I understood, the documentation implies that this plugin snippet should provide a global option to use Maybe I could put it into my store, but this seems like a dirty patch to me. Or did I misunderstand something from the examples? I have been using 1.0-alpha4 |
@tillkolter here is a small repo as a follow up on vuex apollo and vue-apollo: https://github.com/PierBover/vuex-apollo-example-project |
@dohomi I also use your suggested pattern in my app. I must admit not consistently, but I do use it in a lot of cases exactly like that. The problem with your posted solution is, that it wouldn't work with the suggested pattern for Nuxt 1.0 if you want to explicitly make |
You guys are killing me. As a new nuxt user, I naively ran At minimum, update the docs to tell the user to install |
@bjunc Apologies for any inconveniences. First docs are indicating are based on |
Fix of “Error: [nuxt] state should be a function in store/index.js” as explained at nuxt/nuxt#754
Is it possible NOT to make alpha packages as default-latest packages? |
I'm not an NPM expert, but I believe it is possible by using tags (not My request is more simple. Just explicitly put the version number in the installation guide that matches up with the version the documentation is for, and don't sprinkle prerelease examples in. Currently, the doc pages say By the way, I think Nuxt is great – I was just annoyed since I spent hours second guessing myself before I found this thread and realized the docs weren't for the version being pushed out via |
|
Me too: plugins/axios.js
in interceptors got router/store on |
@pi0 are there any news about accessing plugins from within stores? Or is it not recommended to use axios within your store to fetch the data on demand? |
@pi0 How to customize axios ? I want to use an interceptor in the plugin |
Why was this issue closed? 1.0 is still in the release candidate phase. |
@alexchopin this should not be closed, should it? The issues are still not resolved |
Having this issue. Not into switching objects to return functions and back again and so forth. I think Nuxt could implement whatever strategy on the backend but let developers generally code the same way they're used to with Vue. Especially important for those of us maintaining more than one javescript platform (I'm using vue-nativescript, as well as browser support) |
While I've successfully used Nuxt in multiple large projects, I completely agree with @irthos. The main issue with Nuxt is that it's very opinionated (about the way you define things, routing, etc.) without any good reason. One of the main reasons Vue is good is that it's not opinionated on these matters. I wish Nuxt would follow suit. |
@irthos @Etheryte Nuxt.js is opinionated and we know that not everyone will like it, but we tried to enforce best practices to avoid any side-effects with server-side rendering (and yes there is a lot of side effects if you don't respect the best practices). For example, about returning a function for the state in the store files, it's actually Evan who implemented it into Nuxt.js to avoid having the same state between 2 concurrent requests (74652e3#diff-8fac4fd11fc23380db7318a93b0762bd). Nuxt.js is a meta framework which force to use certains tools (Vuex, vue-meta, vue-router), so of course if you want to use other librairies you won't be able with Nuxt, but if you don't mind and look for a framework handling the complexity of code-splitting, asyncData, layouts, pages routing without any configuration, it will be perfect for you ;) |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hello, it seems like 1.0.0-alpha1 has been pushed to npm last night.
My Nuxt.js project is broken now. Can anyone tell, what the breaking changes are?
The text was updated successfully, but these errors were encountered: