Unverified Commit 629884af authored by Yuji Matsumoto's avatar Yuji Matsumoto Committed by GitHub

Update using-preact example's dependencies (#18493)

- Update Next.js version to 10.0.0
- Update the other dependencies
- Modify `next.config.js` to prevent circular `__self` and `__source`in dev env (ref: https://github.com/developit/nextjs-preact-demo/issues/25)
parent 598df6ac
const preact = require('preact')
const withPrefresh = require('@prefresh/next') const withPrefresh = require('@prefresh/next')
module.exports = withPrefresh({ module.exports = withPrefresh({
...@@ -25,15 +26,33 @@ module.exports = withPrefresh({ ...@@ -25,15 +26,33 @@ module.exports = withPrefresh({
const aliases = config.resolve.alias || (config.resolve.alias = {}) const aliases = config.resolve.alias || (config.resolve.alias = {})
aliases.react = aliases['react-dom'] = 'preact/compat' aliases.react = aliases['react-dom'] = 'preact/compat'
if (dev) {
if (isServer) {
// Remove circular `__self` and `__source` props only meant for development
let oldVNodeHook = preact.options.vnode
preact.options.vnode = (vnode) => {
const props = vnode.props
if (props != null) {
if ('__self' in props) props.__self = null
if ('__source' in props) props.__source = null
}
if (oldVNodeHook) {
oldVNodeHook(vnode)
}
}
} else {
// Automatically inject Preact DevTools: // Automatically inject Preact DevTools:
if (dev && !isServer) {
const entry = config.entry const entry = config.entry
config.entry = () => config.entry = () =>
entry().then((entries) => { entry().then((entries) => {
entries['main.js'] = ['preact/debug'].concat(entries['main.js'] || []) entries['main.js'] = ['preact/debug'].concat(
entries['main.js'] || []
)
return entries return entries
}) })
} }
}
return config return config
}, },
......
...@@ -6,17 +6,15 @@ ...@@ -6,17 +6,15 @@
"build": "next build", "build": "next build",
"start": "next start" "start": "next start"
}, },
"devDependencies": { "devDependencies": {},
"react-refresh": "^0.8.3"
},
"dependencies": { "dependencies": {
"@prefresh/next": "^0.3.0", "@prefresh/next": "^1.3.0",
"next": "^9.4.0", "next": "10.0.0",
"preact": "^10.4.4", "preact": "^10.5.4",
"preact-render-to-string": "^5.1.9", "preact-render-to-string": "^5.1.10",
"react": "github:preact-compat/react#1.0.0", "react": "npm:@preact/compat@^0.0.3",
"react-dom": "github:preact-compat/react-dom#1.0.0", "react-dom": "npm:@preact/compat@^0.0.3",
"react-ssr-prepass": "npm:preact-ssr-prepass@^1.0.1" "react-ssr-prepass": "npm:preact-ssr-prepass@^1.1.2"
}, },
"license": "MIT" "license": "MIT"
} }
...@@ -4,9 +4,23 @@ export default function Home() { ...@@ -4,9 +4,23 @@ export default function Home() {
return ( return (
<div> <div>
Hello World.{' '} Hello World.{' '}
<ul>
<li>
<Link href="/about"> <Link href="/about">
<a>About</a> <a>About</a>
</Link> </Link>
</li>
<li>
<Link href="/ssr">
<a>SSR</a>
</Link>
</li>
<li>
<Link href="/ssg">
<a>SSG</a>
</Link>
</li>
</ul>
</div> </div>
) )
} }
export default function SSG({ framework }) {
return <div>{framework} ssg example</div>
}
export function getStaticProps() {
return {
props: { framework: 'preact' },
}
}
export default function SSR({ framework }) {
return <div>{framework} ssr example</div>
}
export function getServerSideProps() {
return {
props: { framework: 'preact' },
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment