Skip to content

Commit c63e80d

Browse files
committed
[WIP] Reduce & Log
1 parent 21bbd46 commit c63e80d

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

packages/next/src/shared/lib/dynamic.tsx

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,21 @@ export function noSSR<P = {}>(
6363
delete loadableOptions.modules
6464

6565
// This check is necessary to prevent react-loadable from initializing on the server
66+
console.log('isServerSide', isServerSide)
6667
if (!isServerSide) {
6768
return LoadableInitializer(loadableOptions)
6869
}
6970

7071
const Loading = loadableOptions.loading!
72+
console.log('Loading: ', Loading)
7173
// This will only be rendered on the server side
72-
return () => (
73-
<Loading error={null} isLoading pastDelay={false} timedOut={false} />
74-
)
74+
return () => {
75+
const el = (
76+
<Loading error={null} isLoading pastDelay={false} timedOut={false} />
77+
)
78+
console.log('el:', el)
79+
return el
80+
}
7581
}
7682

7783
export default function dynamic<P = {}>(
@@ -83,6 +89,7 @@ export default function dynamic<P = {}>(
8389
let loadableOptions: LoadableOptions<P> = {
8490
// A loading component is not required, so we default it
8591
loading: ({ error, isLoading, pastDelay }) => {
92+
console.log(`Render loading: `, { error, isLoading, pastDelay })
8693
if (!pastDelay) return null
8794
if (process.env.NODE_ENV !== 'production') {
8895
if (isLoading) {
@@ -120,11 +127,12 @@ export default function dynamic<P = {}>(
120127
loadableOptions = { ...loadableOptions, ...options }
121128

122129
const loaderFn = loadableOptions.loader as () => LoaderComponent<P>
123-
const loader = () =>
124-
loaderFn != null
130+
const loader = () => {
131+
console.log(`loader called`)
132+
return loaderFn != null
125133
? loaderFn().then(convertModule)
126134
: Promise.resolve(convertModule(() => null))
127-
135+
}
128136
// coming from build/babel/plugins/react-loadable-plugin.js
129137
if (loadableOptions.loadableGenerated) {
130138
loadableOptions = {
@@ -134,6 +142,7 @@ export default function dynamic<P = {}>(
134142
delete loadableOptions.loadableGenerated
135143
}
136144

145+
console.log('LoadableOptions', loadableOptions)
137146
// support for disabling server side rendering, eg: dynamic(() => import('../hello-world'), {ssr: false}).
138147
if (typeof loadableOptions.ssr === 'boolean' && !loadableOptions.ssr) {
139148
delete loadableOptions.webpack

packages/next/src/shared/lib/loadable.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ function load(loader: any) {
4141
loaded: null,
4242
error: null,
4343
}
44-
4544
state.promise = promise
4645
.then((loaded: any) => {
4746
state.loading = false
@@ -138,6 +137,14 @@ function createLoadableComponent(loadFn: any, options: any) {
138137
)
139138

140139
return React.useMemo(() => {
140+
console.log(
141+
'LoadableComponent.state',
142+
state,
143+
'props',
144+
props,
145+
'opts',
146+
opts
147+
)
141148
if (state.loading || state.error) {
142149
return React.createElement(opts.loading, {
143150
isLoading: state.loading,
@@ -147,6 +154,7 @@ function createLoadableComponent(loadFn: any, options: any) {
147154
retry: subscription.retry,
148155
})
149156
} else if (state.loaded) {
157+
console.log('state.loaded', state.loaded)
150158
return React.createElement(resolve(state.loaded), props)
151159
} else {
152160
return null
@@ -254,6 +262,7 @@ class LoadableSubscription {
254262
}
255263

256264
function Loadable(opts: any) {
265+
console.log(`Loadable.opts`, opts)
257266
return createLoadableComponent(load, opts)
258267
}
259268

test/e2e/app-dir/dynamic/app/dynamic/page.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ import {
99
export default function page() {
1010
return (
1111
<div id="content">
12-
<LazyClientComponent />
13-
<NextDynamicServerComponent />
14-
<NextDynamicClientComponent />
15-
<NextDynamicServerImportClientComponent />
1612
<NextDynamicNoSSRServerComponent />
1713
</div>
1814
)

0 commit comments

Comments
 (0)