fix(app): add deprecation warning on using process.browser (#4174)

This commit is contained in:
Przemysław Pietras 2018-10-24 15:47:14 +02:00 committed by Pooya Parsa
parent 96bdcaba01
commit 23228db73c
3 changed files with 39 additions and 6 deletions

View File

@ -156,7 +156,12 @@ async function createApp(ssrContext) {
<% } %>
<% if (store) { %>
if (process.client) {
if (process.client || process.browser) {
<% if (isDev) { %>
if (process.browser) {
console.warn('process.browser is deprecated, use process.client instead.')
}
<% } %>
// Replace store state before plugins execution
if (window.<%= globals.context %> && window.<%= globals.context %>.state) {
store.replaceState(window.<%= globals.context %>.state)
@ -169,7 +174,13 @@ async function createApp(ssrContext) {
<% plugins.filter(p => p.ssr).forEach((plugin) => { %>
if (typeof <%= plugin.name %> === 'function') await <%= plugin.name %>(app.context, inject)<% }) %>
<% if (plugins.filter(p => !p.ssr).length) { %>
if (process.client) { <% plugins.filter((p) => !p.ssr).forEach((plugin) => { %>
if (process.client || process.browser) {
<% if (isDev) { %>
if (process.browser) {
console.warn('process.browser is deprecated, use process.client instead.')
}
<% } %>
<% plugins.filter((p) => !p.ssr).forEach((plugin) => { %>
if (typeof <%= plugin.name %> === 'function') await <%= plugin.name %>(app.context, inject)<% }) %>
}<% } %>
<%= isTest ? '/* eslint-enable camelcase */' : '' %>

View File

@ -51,7 +51,12 @@ Vue.use(Router)
<% if (router.scrollBehavior) { %>
const scrollBehavior = <%= serialize(router.scrollBehavior).replace(/scrollBehavior\s*\(/, 'function(').replace('function function', 'function') %>
<% } else { %>
if (process.client) {
if (process.client || process.browser) {
<% if (isDev) { %>
if (process.browser) {
console.warn('process.browser is deprecated, use process.client instead.')
}
<% } %>
window.history.scrollRestoration = 'manual'
}
const scrollBehavior = function (to, from, savedPosition) {

View File

@ -4,7 +4,13 @@ const noopData = () => ({})
// window.{{globals.loadedCallback}} hook
// Useful for jsdom testing or plugins (https://github.com/tmpvar/jsdom#dealing-with-asynchronous-script-loading)
if (process.client) {
if (process.client || process.browser) {
<% if (isDev) { %>
if (process.browser) {
console.warn('process.browser is deprecated, use process.client instead.')
}
<% } %>
window.<%= globals.readyCallback %>Cbs = []
window.<%= globals.readyCallback %> = (cb) => {
window.<%= globals.readyCallback %>Cbs.push(cb)
@ -165,7 +171,13 @@ export async function setContext(app, context) {
status: status
})
}
if (process.client) {
if (process.client || process.browser) {
<% if (isDev) { %>
if (process.browser) {
console.warn('process.browser is deprecated, use process.client instead.')
}
<% } %>
// https://developer.mozilla.org/en-US/docs/Web/API/Location/replace
window.location.replace(path)
@ -177,7 +189,12 @@ export async function setContext(app, context) {
if (process.server) {
app.context.beforeNuxtRender = fn => context.beforeRenderFns.push(fn)
}
if (process.client) {
if (process.client || process.browser) {
<% if (isDev) { %>
if (process.browser) {
console.warn('process.browser is deprecated, use process.client instead.')
}
<% } %>
app.context.nuxtState = window.<%= globals.context %>
}
}