Skip to content

Commit 41727a5

Browse files
committed
feat(core): make content configurable
BREAKING CHANGE: "Blocks" & "BlockFragment" are now exported under "smooth-code/content"
1 parent a44a436 commit 41727a5

File tree

19 files changed

+177
-121
lines changed

19 files changed

+177
-121
lines changed

packages/smooth-core/blocks.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/smooth-core/content.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./lib/content')

packages/smooth-core/src/blocks.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/smooth-core/src/client/Content.js

Lines changed: 0 additions & 92 deletions
This file was deleted.

packages/smooth-core/src/client/ErrorBoundary.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import React from 'react'
22
import loadable from '@loadable/component'
3-
import Status from './router/Status'
3+
import { Status } from '../router'
44

55
const ErrorPage = loadable(() => import('__smooth_error'))
66

packages/smooth-core/src/client/Page.js

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import React from 'react'
1+
import React, { useRef } from 'react'
22
import loadable from '@loadable/component'
33
import App from '__smooth_app'
4-
import Content from './Content'
4+
import Content from '__smooth_content'
55
import PageContext from './PageContext'
66

77
function getFileName(filePath) {
@@ -54,15 +54,36 @@ export function getPages() {
5454
.sort(sortPages)
5555
}
5656

57-
export default function Page({ page, lang, ...props }) {
57+
export default function Page({
58+
page,
59+
lang,
60+
indexUrl,
61+
history,
62+
match,
63+
location,
64+
}) {
65+
const Component = useRef()
5866
return (
5967
<page.LoadableComponent>
60-
{exp => {
61-
const Component = page.isContent ? Content : exp.default
62-
const appProps = { lang, page, exp, ...props }
68+
{pageModule => {
69+
if (!Component.current) {
70+
Component.current = page.isContent
71+
? function ContentWrapper() {
72+
return <Content Component={pageModule.default} />
73+
}
74+
: pageModule.default
75+
}
76+
77+
const pageContext = {
78+
lang,
79+
page: { ...page, module: pageModule, indexUrl },
80+
history,
81+
match,
82+
location,
83+
}
6384
return (
64-
<PageContext.Provider value={{ lang, page }}>
65-
<App {...appProps} Component={Component} />
85+
<PageContext.Provider value={pageContext}>
86+
<App {...pageContext} Component={Component.current} />
6687
</PageContext.Provider>
6788
)
6889
}}

packages/smooth-core/src/client/Routes.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,14 @@ export default function Routes() {
1919
<Route
2020
key={index}
2121
path={`${url}${page.routePath}`}
22-
render={routeProps => (
22+
render={({ history, match, location }) => (
2323
<Page
2424
lang={lang}
2525
indexUrl={`${url}${page.indexPath}`}
2626
page={page}
27-
{...routeProps}
27+
history={history}
28+
match={match}
29+
location={location}
2830
/>
2931
)}
3032
/>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { default } from '../content'

packages/smooth-core/src/client/router/Status.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

packages/smooth-core/src/config/webpack.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ function getTargetConfig(target, { config, dev }) {
7171
__smooth_app: getScriptPath(config, '_app.js'),
7272
__smooth_document: getScriptPath(config, '_document.js'),
7373
__smooth_error: getScriptPath(config, '_error.js'),
74+
__smooth_content: getScriptPath(config, '_content.js'),
7475
__smooth_blocks: config.blocksPath,
7576
__smooth_pages: config.pagesPath,
7677
},

0 commit comments

Comments
 (0)