Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
N
next.js
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Alex
next.js
Commits
c03e94be
Unverified
Commit
c03e94be
authored
Jun 24, 2019
by
Joe Haddad
Committed by
GitHub
Jun 24, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove usage of `process.browser` (#7651)
parent
ee2bdb89
Hide whitespace changes
Inline
Side-by-side
Showing
26 changed files
with
51 additions
and
45 deletions
+51
-45
initApollo.js
examples/with-apollo-and-redux-saga/lib/initApollo.js
+5
-4
withApollo.js
examples/with-apollo-and-redux-saga/lib/withApollo.js
+1
-1
initApollo.js
examples/with-apollo-and-redux/lib/initApollo.js
+5
-4
withApollo.js
examples/with-apollo-and-redux/lib/withApollo.js
+1
-1
initApollo.js
examples/with-apollo-auth/lib/initApollo.js
+5
-4
withApollo.js
examples/with-apollo-auth/lib/withApollo.js
+1
-1
init-apollo.js
examples/with-apollo/lib/init-apollo.js
+5
-4
with-apollo-client.js
examples/with-apollo/lib/with-apollo-client.js
+1
-1
profile.js
examples/with-cookie-auth/www/pages/profile.js
+1
-1
init-graphql.js
examples/with-graphql-hooks/lib/init-graphql.js
+3
-3
with-graphql-client.js
examples/with-graphql-hooks/lib/with-graphql-client.js
+1
-1
store.js
examples/with-mobx-react-lite/store.js
+1
-1
_app.js
examples/with-mobx/pages/_app.js
+1
-1
store.js
examples/with-mobx/store.js
+1
-1
_app.js
examples/with-overmind/pages/_app.js
+1
-1
_app.js
examples/with-portals-ssr/pages/_app.js
+1
-1
BreakingNews.js
examples/with-react-esi/src/components/BreakingNews.js
+3
-2
Weather.js
examples/with-react-esi/src/components/Weather.js
+2
-2
getPageContext.js
examples/with-react-multi-carousel/src/getPageContext.js
+1
-1
index.js
...react-relay-network-modern/lib/createEnvironment/index.js
+2
-1
index.js
examples/with-react-uwp/pages/index.js
+1
-1
createRelayEnvironment.js
...relay-modern-server-express/lib/createRelayEnvironment.js
+3
-2
createRelayEnvironment.js
examples/with-relay-modern/lib/createRelayEnvironment.js
+1
-1
sentry.js
examples/with-sentry/utils/sentry.js
+1
-2
_app.js
examples/with-unstated/pages/_app.js
+2
-2
data.ts
packages/next/lib/data.ts
+1
-1
No files found.
examples/with-apollo-and-redux-saga/lib/initApollo.js
View file @
c03e94be
...
@@ -6,15 +6,16 @@ import fetch from 'isomorphic-unfetch'
...
@@ -6,15 +6,16 @@ import fetch from 'isomorphic-unfetch'
let
apolloClient
=
null
let
apolloClient
=
null
// Polyfill fetch() on the server (used by apollo-client)
// Polyfill fetch() on the server (used by apollo-client)
if
(
!
process
.
browser
)
{
if
(
typeof
window
===
'undefined'
)
{
global
.
fetch
=
fetch
global
.
fetch
=
fetch
}
}
function
create
(
initialState
)
{
function
create
(
initialState
)
{
const
isBrowser
=
typeof
window
!==
'undefined'
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
return
new
ApolloClient
({
return
new
ApolloClient
({
connectToDevTools
:
process
.
b
rowser
,
connectToDevTools
:
isB
rowser
,
ssrMode
:
!
process
.
b
rowser
,
// Disables forceFetch on the server (so queries are only run once)
ssrMode
:
!
isB
rowser
,
// Disables forceFetch on the server (so queries are only run once)
link
:
new
HttpLink
({
link
:
new
HttpLink
({
uri
:
'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn'
,
// Server URL (must be absolute)
uri
:
'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn'
,
// Server URL (must be absolute)
credentials
:
'same-origin'
// Additional fetch() options like `credentials` or `headers`
credentials
:
'same-origin'
// Additional fetch() options like `credentials` or `headers`
...
@@ -26,7 +27,7 @@ function create (initialState) {
...
@@ -26,7 +27,7 @@ function create (initialState) {
export
default
function
initApollo
(
initialState
)
{
export
default
function
initApollo
(
initialState
)
{
// Make sure to create a new client for every server-side request so that data
// Make sure to create a new client for every server-side request so that data
// isn't shared between connections (which would be bad)
// isn't shared between connections (which would be bad)
if
(
!
process
.
browser
)
{
if
(
typeof
window
===
'undefined'
)
{
return
create
(
initialState
)
return
create
(
initialState
)
}
}
...
...
examples/with-apollo-and-redux-saga/lib/withApollo.js
View file @
c03e94be
...
@@ -34,7 +34,7 @@ export default ComposedComponent => {
...
@@ -34,7 +34,7 @@ export default ComposedComponent => {
// Run all GraphQL queries in the component tree
// Run all GraphQL queries in the component tree
// and extract the resulting data
// and extract the resulting data
if
(
!
process
.
browser
)
{
if
(
typeof
window
===
'undefined'
)
{
const
apollo
=
initApollo
()
const
apollo
=
initApollo
()
try
{
try
{
...
...
examples/with-apollo-and-redux/lib/initApollo.js
View file @
c03e94be
...
@@ -6,15 +6,16 @@ import fetch from 'isomorphic-unfetch'
...
@@ -6,15 +6,16 @@ import fetch from 'isomorphic-unfetch'
let
apolloClient
=
null
let
apolloClient
=
null
// Polyfill fetch() on the server (used by apollo-client)
// Polyfill fetch() on the server (used by apollo-client)
if
(
!
process
.
browser
)
{
if
(
typeof
window
===
'undefined'
)
{
global
.
fetch
=
fetch
global
.
fetch
=
fetch
}
}
function
create
(
initialState
)
{
function
create
(
initialState
)
{
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
const
isBrowser
=
typeof
window
!==
'undefined'
return
new
ApolloClient
({
return
new
ApolloClient
({
connectToDevTools
:
process
.
b
rowser
,
connectToDevTools
:
isB
rowser
,
ssrMode
:
!
process
.
b
rowser
,
// Disables forceFetch on the server (so queries are only run once)
ssrMode
:
!
isB
rowser
,
// Disables forceFetch on the server (so queries are only run once)
link
:
new
HttpLink
({
link
:
new
HttpLink
({
uri
:
'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn'
,
// Server URL (must be absolute)
uri
:
'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn'
,
// Server URL (must be absolute)
credentials
:
'same-origin'
// Additional fetch() options like `credentials` or `headers`
credentials
:
'same-origin'
// Additional fetch() options like `credentials` or `headers`
...
@@ -26,7 +27,7 @@ function create (initialState) {
...
@@ -26,7 +27,7 @@ function create (initialState) {
export
default
function
initApollo
(
initialState
)
{
export
default
function
initApollo
(
initialState
)
{
// Make sure to create a new client for every server-side request so that data
// Make sure to create a new client for every server-side request so that data
// isn't shared between connections (which would be bad)
// isn't shared between connections (which would be bad)
if
(
!
process
.
browser
)
{
if
(
typeof
window
===
'undefined'
)
{
return
create
(
initialState
)
return
create
(
initialState
)
}
}
...
...
examples/with-apollo-and-redux/lib/withApollo.js
View file @
c03e94be
...
@@ -34,7 +34,7 @@ export default ComposedComponent => {
...
@@ -34,7 +34,7 @@ export default ComposedComponent => {
// Run all GraphQL queries in the component tree
// Run all GraphQL queries in the component tree
// and extract the resulting data
// and extract the resulting data
if
(
!
process
.
browser
)
{
if
(
typeof
window
===
'undefined'
)
{
const
apollo
=
initApollo
()
const
apollo
=
initApollo
()
try
{
try
{
...
...
examples/with-apollo-auth/lib/initApollo.js
View file @
c03e94be
...
@@ -6,7 +6,7 @@ import fetch from 'isomorphic-unfetch'
...
@@ -6,7 +6,7 @@ import fetch from 'isomorphic-unfetch'
let
apolloClient
=
null
let
apolloClient
=
null
// Polyfill fetch() on the server (used by apollo-client)
// Polyfill fetch() on the server (used by apollo-client)
if
(
!
process
.
browser
)
{
if
(
typeof
window
===
'undefined'
)
{
global
.
fetch
=
fetch
global
.
fetch
=
fetch
}
}
...
@@ -28,9 +28,10 @@ function create (initialState, { getToken, fetchOptions }) {
...
@@ -28,9 +28,10 @@ function create (initialState, { getToken, fetchOptions }) {
})
})
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
const
isBrowser
=
typeof
window
!==
'undefined'
return
new
ApolloClient
({
return
new
ApolloClient
({
connectToDevTools
:
process
.
b
rowser
,
connectToDevTools
:
isB
rowser
,
ssrMode
:
!
process
.
b
rowser
,
// Disables forceFetch on the server (so queries are only run once)
ssrMode
:
!
isB
rowser
,
// Disables forceFetch on the server (so queries are only run once)
link
:
authLink
.
concat
(
httpLink
),
link
:
authLink
.
concat
(
httpLink
),
cache
:
new
InMemoryCache
().
restore
(
initialState
||
{})
cache
:
new
InMemoryCache
().
restore
(
initialState
||
{})
})
})
...
@@ -39,7 +40,7 @@ function create (initialState, { getToken, fetchOptions }) {
...
@@ -39,7 +40,7 @@ function create (initialState, { getToken, fetchOptions }) {
export
default
function
initApollo
(
initialState
,
options
)
{
export
default
function
initApollo
(
initialState
,
options
)
{
// Make sure to create a new client for every server-side request so that data
// Make sure to create a new client for every server-side request so that data
// isn't shared between connections (which would be bad)
// isn't shared between connections (which would be bad)
if
(
!
process
.
browser
)
{
if
(
typeof
window
===
'undefined'
)
{
let
fetchOptions
=
{}
let
fetchOptions
=
{}
// If you are using a https_proxy, add fetchOptions with 'https-proxy-agent' agent instance
// If you are using a https_proxy, add fetchOptions with 'https-proxy-agent' agent instance
// 'https-proxy-agent' is required here because it's a sever-side only module
// 'https-proxy-agent' is required here because it's a sever-side only module
...
...
examples/with-apollo-auth/lib/withApollo.js
View file @
c03e94be
...
@@ -43,7 +43,7 @@ export default App => {
...
@@ -43,7 +43,7 @@ export default App => {
return
{}
return
{}
}
}
if
(
!
process
.
browser
)
{
if
(
typeof
window
===
'undefined'
)
{
// Run all graphql queries in the component tree
// Run all graphql queries in the component tree
// and extract the resulting data
// and extract the resulting data
try
{
try
{
...
...
examples/with-apollo/lib/init-apollo.js
View file @
c03e94be
...
@@ -5,14 +5,15 @@ let apolloClient = null
...
@@ -5,14 +5,15 @@ let apolloClient = null
function
create
(
initialState
)
{
function
create
(
initialState
)
{
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
// Check out https://github.com/zeit/next.js/pull/4611 if you want to use the AWSAppSyncClient
const
isBrowser
=
typeof
window
!==
'undefined'
return
new
ApolloClient
({
return
new
ApolloClient
({
connectToDevTools
:
process
.
b
rowser
,
connectToDevTools
:
isB
rowser
,
ssrMode
:
!
process
.
b
rowser
,
// Disables forceFetch on the server (so queries are only run once)
ssrMode
:
!
isB
rowser
,
// Disables forceFetch on the server (so queries are only run once)
link
:
new
HttpLink
({
link
:
new
HttpLink
({
uri
:
'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn'
,
// Server URL (must be absolute)
uri
:
'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn'
,
// Server URL (must be absolute)
credentials
:
'same-origin'
,
// Additional fetch() options like `credentials` or `headers`
credentials
:
'same-origin'
,
// Additional fetch() options like `credentials` or `headers`
// Use fetch() polyfill on the server
// Use fetch() polyfill on the server
fetch
:
!
process
.
b
rowser
&&
fetch
fetch
:
!
isB
rowser
&&
fetch
}),
}),
cache
:
new
InMemoryCache
().
restore
(
initialState
||
{})
cache
:
new
InMemoryCache
().
restore
(
initialState
||
{})
})
})
...
@@ -21,7 +22,7 @@ function create (initialState) {
...
@@ -21,7 +22,7 @@ function create (initialState) {
export
default
function
initApollo
(
initialState
)
{
export
default
function
initApollo
(
initialState
)
{
// Make sure to create a new client for every server-side request so that data
// Make sure to create a new client for every server-side request so that data
// isn't shared between connections (which would be bad)
// isn't shared between connections (which would be bad)
if
(
!
process
.
browser
)
{
if
(
typeof
window
===
'undefined'
)
{
return
create
(
initialState
)
return
create
(
initialState
)
}
}
...
...
examples/with-apollo/lib/with-apollo-client.js
View file @
c03e94be
...
@@ -17,7 +17,7 @@ export default App => {
...
@@ -17,7 +17,7 @@ export default App => {
// Run all GraphQL queries in the component tree
// Run all GraphQL queries in the component tree
// and extract the resulting data
// and extract the resulting data
const
apollo
=
initApollo
()
const
apollo
=
initApollo
()
if
(
!
process
.
browser
)
{
if
(
typeof
window
===
'undefined'
)
{
try
{
try
{
// Run all GraphQL queries
// Run all GraphQL queries
await
getDataFromTree
(
await
getDataFromTree
(
...
...
examples/with-cookie-auth/www/pages/profile.js
View file @
c03e94be
...
@@ -44,7 +44,7 @@ Profile.getInitialProps = async ctx => {
...
@@ -44,7 +44,7 @@ Profile.getInitialProps = async ctx => {
const
url
=
`
${
process
.
env
.
API_URL
}
/api/profile.js`
const
url
=
`
${
process
.
env
.
API_URL
}
/api/profile.js`
const
redirectOnError
=
()
=>
const
redirectOnError
=
()
=>
process
.
browser
typeof
window
!==
'undefined'
?
Router
.
push
(
'/login'
)
?
Router
.
push
(
'/login'
)
:
ctx
.
res
.
writeHead
(
302
,
{
Location
:
'/login'
}).
end
()
:
ctx
.
res
.
writeHead
(
302
,
{
Location
:
'/login'
}).
end
()
...
...
examples/with-graphql-hooks/lib/init-graphql.js
View file @
c03e94be
...
@@ -6,17 +6,17 @@ let graphQLClient = null
...
@@ -6,17 +6,17 @@ let graphQLClient = null
function
create
(
initialState
=
{})
{
function
create
(
initialState
=
{})
{
return
new
GraphQLClient
({
return
new
GraphQLClient
({
ssrMode
:
!
process
.
browser
,
ssrMode
:
typeof
window
===
'undefined'
,
url
:
'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn'
,
url
:
'https://api.graph.cool/simple/v1/cixmkt2ul01q00122mksg82pn'
,
cache
:
memCache
({
initialState
}),
cache
:
memCache
({
initialState
}),
fetch
:
process
.
browser
?
fetch
.
bind
()
:
unfetch
,
// eslint-disable-line
fetch
:
typeof
window
!==
'undefined'
?
fetch
.
bind
()
:
unfetch
,
// eslint-disable-line
})
})
}
}
export
default
function
initGraphQL
(
initialState
)
{
export
default
function
initGraphQL
(
initialState
)
{
// Make sure to create a new client for every server-side request so that data
// Make sure to create a new client for every server-side request so that data
// isn't shared between connections (which would be bad)
// isn't shared between connections (which would be bad)
if
(
!
process
.
browser
)
{
if
(
typeof
window
===
'undefined'
)
{
return
create
(
initialState
)
return
create
(
initialState
)
}
}
...
...
examples/with-graphql-hooks/lib/with-graphql-client.js
View file @
c03e94be
...
@@ -18,7 +18,7 @@ export default App => {
...
@@ -18,7 +18,7 @@ export default App => {
// and extract the resulting data
// and extract the resulting data
const
graphQLClient
=
initGraphQL
()
const
graphQLClient
=
initGraphQL
()
let
graphQLState
=
{}
let
graphQLState
=
{}
if
(
!
process
.
browser
)
{
if
(
typeof
window
===
'undefined'
)
{
try
{
try
{
// Run all GraphQL queries
// Run all GraphQL queries
graphQLState
=
await
getInitialState
({
graphQLState
=
await
getInitialState
({
...
...
examples/with-mobx-react-lite/store.js
View file @
c03e94be
...
@@ -2,7 +2,7 @@ import { action } from 'mobx'
...
@@ -2,7 +2,7 @@ import { action } from 'mobx'
import
{
useObservable
,
useStaticRendering
}
from
'mobx-react-lite'
import
{
useObservable
,
useStaticRendering
}
from
'mobx-react-lite'
import
{
createContext
,
useCallback
}
from
'react'
import
{
createContext
,
useCallback
}
from
'react'
const
isServer
=
!
process
.
browser
const
isServer
=
typeof
window
===
'undefined'
useStaticRendering
(
isServer
)
useStaticRendering
(
isServer
)
let
StoreContext
=
createContext
()
let
StoreContext
=
createContext
()
...
...
examples/with-mobx/pages/_app.js
View file @
c03e94be
...
@@ -21,7 +21,7 @@ class MyMobxApp extends App {
...
@@ -21,7 +21,7 @@ class MyMobxApp extends App {
constructor
(
props
)
{
constructor
(
props
)
{
super
(
props
)
super
(
props
)
const
isServer
=
!
process
.
browser
const
isServer
=
typeof
window
===
'undefined'
this
.
mobxStore
=
isServer
this
.
mobxStore
=
isServer
?
props
.
initialMobxState
?
props
.
initialMobxState
:
initializeStore
(
props
.
initialMobxState
)
:
initializeStore
(
props
.
initialMobxState
)
...
...
examples/with-mobx/store.js
View file @
c03e94be
import
{
action
,
observable
}
from
'mobx'
import
{
action
,
observable
}
from
'mobx'
import
{
useStaticRendering
}
from
'mobx-react'
import
{
useStaticRendering
}
from
'mobx-react'
const
isServer
=
!
process
.
browser
const
isServer
=
typeof
window
===
'undefined'
useStaticRendering
(
isServer
)
useStaticRendering
(
isServer
)
class
Store
{
class
Store
{
...
...
examples/with-overmind/pages/_app.js
View file @
c03e94be
...
@@ -24,7 +24,7 @@ class MyApp extends App {
...
@@ -24,7 +24,7 @@ class MyApp extends App {
const
mutations
=
props
.
pageProps
.
mutations
||
[]
const
mutations
=
props
.
pageProps
.
mutations
||
[]
if
(
process
.
browser
)
{
if
(
typeof
window
!==
'undefined'
)
{
// On the client we just instantiate the Overmind instance and run
// On the client we just instantiate the Overmind instance and run
// the "changePage" action
// the "changePage" action
this
.
overmind
=
createOvermind
(
config
)
this
.
overmind
=
createOvermind
(
config
)
...
...
examples/with-portals-ssr/pages/_app.js
View file @
c03e94be
...
@@ -2,7 +2,7 @@ import React from 'react'
...
@@ -2,7 +2,7 @@ import React from 'react'
import
App
,
{
Container
}
from
'next/app'
import
App
,
{
Container
}
from
'next/app'
import
{
prepareClientPortals
}
from
'@jesstelford/react-portal-universal'
import
{
prepareClientPortals
}
from
'@jesstelford/react-portal-universal'
if
(
process
.
browser
)
{
if
(
typeof
window
!==
'undefined'
)
{
// On the client, we have to run this once before React attempts a render.
// On the client, we have to run this once before React attempts a render.
// Here in _app is a great place to do it as this file is only required once,
// Here in _app is a great place to do it as this file is only required once,
// and right now (outside the constructor) is before React is invoked.
// and right now (outside the constructor) is before React is invoked.
...
...
examples/with-react-esi/src/components/BreakingNews.js
View file @
c03e94be
...
@@ -11,8 +11,9 @@ const BreakingNews = props => (
...
@@ -11,8 +11,9 @@ const BreakingNews = props => (
<
p
>
{
breaking
.
body
}
<
/p
>
<
p
>
{
breaking
.
body
}
<
/p
>
<
/article
>
<
/article
>
))}
))}
We
are
<
b
>
{
process
.
browser
?
'client-side'
:
'server-side'
}
<
/b>
(
now, chec
k
We
are
{
' '
}
the
source
of
this
page
)
<
b
>
{
typeof
window
!==
'undefined'
?
'client-side'
:
'server-side'
}
<
/b>
(
now
,
check
the
source
of
this
page
)
<
div
>
<
div
>
<
small
>
generated
at
{
new
Date
().
toISOString
()}
<
/small
>
<
small
>
generated
at
{
new
Date
().
toISOString
()}
<
/small
>
<
/div
>
<
/div
>
...
...
examples/with-react-esi/src/components/Weather.js
View file @
c03e94be
...
@@ -7,7 +7,7 @@ export default class TopArticles extends React.Component {
...
@@ -7,7 +7,7 @@ export default class TopArticles extends React.Component {
static
async
getInitialProps
({
props
,
req
,
res
})
{
static
async
getInitialProps
({
props
,
req
,
res
})
{
// Fetch the weather from a remote API, it may take some time...
// Fetch the weather from a remote API, it may take some time...
return
new
Promise
(
resolve
=>
{
return
new
Promise
(
resolve
=>
{
console
.
log
(
process
.
browser
?
'client-side'
:
'server-side'
)
console
.
log
(
typeof
window
!==
'undefined'
?
'client-side'
:
'server-side'
)
// Simulate a delay (slow network, huge computation...)
// Simulate a delay (slow network, huge computation...)
setTimeout
(
setTimeout
(
()
=>
()
=>
...
@@ -21,7 +21,7 @@ export default class TopArticles extends React.Component {
...
@@ -21,7 +21,7 @@ export default class TopArticles extends React.Component {
}
}
render
()
{
render
()
{
console
.
log
(
process
.
browser
?
'client-side'
:
'server-side'
)
console
.
log
(
typeof
window
!==
'undefined'
?
'client-side'
:
'server-side'
)
return
(
return
(
<
section
>
<
section
>
...
...
examples/with-react-multi-carousel/src/getPageContext.js
View file @
c03e94be
...
@@ -43,7 +43,7 @@ let pageContext
...
@@ -43,7 +43,7 @@ let pageContext
export
default
function
getPageContext
()
{
export
default
function
getPageContext
()
{
// Make sure to create a new context for every server-side request so that data
// Make sure to create a new context for every server-side request so that data
// isn't shared between connections (which would be bad).
// isn't shared between connections (which would be bad).
if
(
!
process
.
browser
)
{
if
(
typeof
window
===
'undefined'
)
{
return
createPageContext
()
return
createPageContext
()
}
}
...
...
examples/with-react-relay-network-modern/lib/createEnvironment/index.js
View file @
c03e94be
import
'isomorphic-fetch'
import
'isomorphic-fetch'
export
const
{
initEnvironment
,
createEnvironment
}
=
(
!
process
.
browser
export
const
{
initEnvironment
,
createEnvironment
}
=
(
typeof
window
===
'undefined'
?
require
(
'./server'
)
?
require
(
'./server'
)
:
require
(
'./client'
)
:
require
(
'./client'
)
).
default
).
default
examples/with-react-uwp/pages/index.js
View file @
c03e94be
...
@@ -9,7 +9,7 @@ import { Button, ColorPicker, DatePicker, ProgressRing } from 'react-uwp'
...
@@ -9,7 +9,7 @@ import { Button, ColorPicker, DatePicker, ProgressRing } from 'react-uwp'
class
Index
extends
Component
{
class
Index
extends
Component
{
static
async
getInitialProps
({
req
})
{
static
async
getInitialProps
({
req
})
{
let
userAgent
let
userAgent
if
(
process
.
browser
)
{
if
(
typeof
window
!==
'undefined'
)
{
userAgent
=
navigator
.
userAgent
userAgent
=
navigator
.
userAgent
}
else
{
}
else
{
userAgent
=
req
.
headers
[
'user-agent'
]
userAgent
=
req
.
headers
[
'user-agent'
]
...
...
examples/with-relay-modern-server-express/lib/createRelayEnvironment.js
View file @
c03e94be
...
@@ -7,7 +7,8 @@ let relayEnvironment = null
...
@@ -7,7 +7,8 @@ let relayEnvironment = null
// and returns its results as a Promise:
// and returns its results as a Promise:
function
fetchQuery
(
operation
,
variables
,
cacheConfig
,
uploadables
)
{
function
fetchQuery
(
operation
,
variables
,
cacheConfig
,
uploadables
)
{
// Because we implement the graphql server, the client must to point to the same host
// Because we implement the graphql server, the client must to point to the same host
const
relayServer
=
process
.
browser
?
''
:
process
.
env
.
RELAY_SERVER
const
relayServer
=
typeof
window
!==
'undefined'
?
''
:
process
.
env
.
RELAY_SERVER
return
fetch
(
`
${
relayServer
}
/graphql`
,
{
return
fetch
(
`
${
relayServer
}
/graphql`
,
{
method
:
'POST'
,
method
:
'POST'
,
headers
:
{
headers
:
{
...
@@ -28,7 +29,7 @@ export default function initEnvironment ({ records = {} } = {}) {
...
@@ -28,7 +29,7 @@ export default function initEnvironment ({ records = {} } = {}) {
// Make sure to create a new Relay environment for every server-side request so that data
// Make sure to create a new Relay environment for every server-side request so that data
// isn't shared between connections (which would be bad)
// isn't shared between connections (which would be bad)
if
(
!
process
.
browser
)
{
if
(
typeof
window
===
'undefined'
)
{
return
new
Environment
({
return
new
Environment
({
network
,
network
,
store
store
...
...
examples/with-relay-modern/lib/createRelayEnvironment.js
View file @
c03e94be
...
@@ -26,7 +26,7 @@ export default function initEnvironment ({ records = {} } = {}) {
...
@@ -26,7 +26,7 @@ export default function initEnvironment ({ records = {} } = {}) {
// Make sure to create a new Relay environment for every server-side request so that data
// Make sure to create a new Relay environment for every server-side request so that data
// isn't shared between connections (which would be bad)
// isn't shared between connections (which would be bad)
if
(
!
process
.
browser
)
{
if
(
typeof
window
===
'undefined'
)
{
return
new
Environment
({
return
new
Environment
({
network
,
network
,
store
store
...
...
examples/with-sentry/utils/sentry.js
View file @
c03e94be
// NOTE: This require will be replaced with `@sentry/browser` when
// NOTE: This require will be replaced with `@sentry/browser` when
// process.browser === true thanks to the webpack config in next.config.js
const
Sentry
=
require
(
'@sentry/node'
)
const
Sentry
=
require
(
'@sentry/node'
)
const
SentryIntegrations
=
require
(
'@sentry/integrations'
)
const
SentryIntegrations
=
require
(
'@sentry/integrations'
)
const
Cookie
=
require
(
'js-cookie'
)
const
Cookie
=
require
(
'js-cookie'
)
...
@@ -53,7 +52,7 @@ module.exports = (release = process.env.SENTRY_RELEASE) => {
...
@@ -53,7 +52,7 @@ module.exports = (release = process.env.SENTRY_RELEASE) => {
scope
.
setExtra
(
'statusCode'
,
res
.
statusCode
)
scope
.
setExtra
(
'statusCode'
,
res
.
statusCode
)
}
}
if
(
process
.
browser
)
{
if
(
typeof
window
!==
'undefined'
)
{
scope
.
setTag
(
'ssr'
,
false
)
scope
.
setTag
(
'ssr'
,
false
)
scope
.
setExtra
(
'query'
,
query
)
scope
.
setExtra
(
'query'
,
query
)
scope
.
setExtra
(
'pathname'
,
pathname
)
scope
.
setExtra
(
'pathname'
,
pathname
)
...
...
examples/with-unstated/pages/_app.js
View file @
c03e94be
...
@@ -6,7 +6,7 @@ import { counterStore } from '../containers/CounterContainer'
...
@@ -6,7 +6,7 @@ import { counterStore } from '../containers/CounterContainer'
class
MyApp
extends
App
{
class
MyApp
extends
App
{
static
async
getInitialProps
()
{
static
async
getInitialProps
()
{
// do your server state here
// do your server state here
if
(
!
process
.
browser
)
{
if
(
typeof
window
===
'undefined'
)
{
// reset state for each request
// reset state for each request
counterStore
.
resetState
()
counterStore
.
resetState
()
// process state, in this case counter start with 999
// process state, in this case counter start with 999
...
@@ -20,7 +20,7 @@ class MyApp extends App {
...
@@ -20,7 +20,7 @@ class MyApp extends App {
super
(
props
)
super
(
props
)
// pass the state to client store
// pass the state to client store
// serverState will be reset when client navigate with Link
// serverState will be reset when client navigate with Link
if
(
process
.
browser
)
{
if
(
typeof
window
!==
'undefined'
)
{
counterStore
.
initState
(
props
.
serverState
.
count
)
counterStore
.
initState
(
props
.
serverState
.
count
)
}
}
}
}
...
...
packages/next/lib/data.ts
View file @
c03e94be
...
@@ -47,7 +47,7 @@ export function createHook(
...
@@ -47,7 +47,7 @@ export function createHook(
}
}
// @ts-ignore webpack optimization
// @ts-ignore webpack optimization
if
(
process
.
browser
)
{
if
(
typeof
window
!==
'undefined'
)
{
const
res
=
fetch
(
router
.
route
+
'?'
+
stringify
(
router
.
query
),
{
const
res
=
fetch
(
router
.
route
+
'?'
+
stringify
(
router
.
query
),
{
headers
:
{
headers
:
{
accept
:
'application/amp.bind+json'
,
accept
:
'application/amp.bind+json'
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment