diff --git a/packages/async-loader/async-legacy.js b/packages/async-loader/async-legacy.js deleted file mode 100644 index a408d1273..000000000 --- a/packages/async-loader/async-legacy.js +++ /dev/null @@ -1,36 +0,0 @@ -import { h, Component } from 'preact'; - -export default function (req) { - function Async() { - Component.call(this); - - let b, old; - this.componentWillMount = () => { - b = this.base = this.nextBase || this.__b; // short circuits 1st render - req(m => { - this.setState({ child: m.default || m }); - }); - }; - - this.shouldComponentUpdate = (_, nxt) => { - nxt = nxt.child === void 0; - if (nxt && old === void 0 && b) { - // Node.TEXT_NODE - if (b.nodeType === 3) { - old = b.data; - } else { - old = h(b.nodeName, { - dangerouslySetInnerHTML: { __html: b.innerHTML }, - }); - } - } else { - old = ''; // dump it - } - return !nxt; - }; - - this.render = (p, s) => (s.child ? h(s.child, p) : old); - } - (Async.prototype = new Component()).constructor = Async; - return Async; -} diff --git a/packages/async-loader/legacy.js b/packages/async-loader/legacy.js deleted file mode 100644 index f77d66c84..000000000 --- a/packages/async-loader/legacy.js +++ /dev/null @@ -1,8 +0,0 @@ -const { pitch, PREACT_LEGACY_MODE } = require('.'); -const { info } = require('./utils'); - -info('Detected Preact 8, Loading legacy async-component'); - -exports.pitch = function (req) { - return pitch(req, PREACT_LEGACY_MODE); -}; diff --git a/packages/async-loader/package.json b/packages/async-loader/package.json index ada800699..3446bb461 100644 --- a/packages/async-loader/package.json +++ b/packages/async-loader/package.json @@ -18,7 +18,6 @@ "node": ">=8" }, "dependencies": { - "kleur": "^4.1.4", "loader-utils": "^2.0.0" }, "peerDependencies": { diff --git a/packages/async-loader/utils.js b/packages/async-loader/utils.js deleted file mode 100644 index 765d6aad0..000000000 --- a/packages/async-loader/utils.js +++ /dev/null @@ -1,6 +0,0 @@ -const { blue } = require('kleur'); - -exports.info = function (text, code) { - process.stderr.write('\n' + blue('ℹ INFO: ⚛️ ') + text + '\n'); - code && process.exit(code); -}; diff --git a/packages/cli/lib/lib/webpack/utils.js b/packages/cli/lib/lib/webpack/utils.js deleted file mode 100644 index 20dcccf4a..000000000 --- a/packages/cli/lib/lib/webpack/utils.js +++ /dev/null @@ -1,16 +0,0 @@ -function isInstalledVersionPreactXOrAbove(cwd) { - try { - return ( - parseInt( - require(require.resolve('preact/package.json', { paths: [cwd] })) - .version, - 10 - ) >= 10 - ); - } catch (e) {} - return false; -} - -module.exports = { - isInstalledVersionPreactXOrAbove, -}; diff --git a/packages/cli/lib/lib/webpack/webpack-base-config.js b/packages/cli/lib/lib/webpack/webpack-base-config.js index 54cb199c4..e03f2e38a 100644 --- a/packages/cli/lib/lib/webpack/webpack-base-config.js +++ b/packages/cli/lib/lib/webpack/webpack-base-config.js @@ -2,7 +2,6 @@ const webpack = require('webpack'); const path = require('path'); const { resolve, dirname } = require('path'); const { readFileSync, existsSync } = require('fs'); -const { isInstalledVersionPreactXOrAbove } = require('./utils'); const autoprefixer = require('autoprefixer'); const browserslist = require('browserslist'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); @@ -72,7 +71,6 @@ function getSassConfiguration(...includePaths) { module.exports = function createBaseConfig(env) { const { cwd, isProd, isWatch, src, source } = env; const babelConfigFile = env.babelConfig || '.babelrc'; - const IS_SOURCE_PREACT_X_OR_ABOVE = isInstalledVersionPreactXOrAbove(cwd); // Apply base-level `env` values env.dest = resolve(cwd, env.dest || 'build'); env.manifest = readJson(source('manifest.json')) || {}; @@ -153,9 +151,9 @@ module.exports = function createBaseConfig(env) { 'react-dom': compat, 'preact-compat': compat, 'react-addons-css-transition-group': 'preact-css-transition-group', - 'preact-cli/async-component': IS_SOURCE_PREACT_X_OR_ABOVE - ? require.resolve('@preact/async-loader/async') - : require.resolve('@preact/async-loader/async-legacy'), + 'preact-cli/async-component': require.resolve( + '@preact/async-loader/async' + ), }, }, diff --git a/packages/cli/lib/lib/webpack/webpack-client-config.js b/packages/cli/lib/lib/webpack/webpack-client-config.js index e546d8e0f..588ad4fc6 100644 --- a/packages/cli/lib/lib/webpack/webpack-client-config.js +++ b/packages/cli/lib/lib/webpack/webpack-client-config.js @@ -1,7 +1,6 @@ const webpack = require('webpack'); const { resolve, join } = require('path'); const { existsSync } = require('fs'); -const { isInstalledVersionPreactXOrAbove } = require('./utils'); const { merge } = require('webpack-merge'); const { filter } = require('minimatch'); const SizePlugin = require('size-plugin'); @@ -25,12 +24,12 @@ const cleanFilename = name => '' ); +/** + * @returns {Promise} + */ async function clientConfig(env) { - const { isProd, source, src, cwd /*, port? */ } = env; - const IS_SOURCE_PREACT_X_OR_ABOVE = isInstalledVersionPreactXOrAbove(cwd); - const asyncLoader = IS_SOURCE_PREACT_X_OR_ABOVE - ? require.resolve('@preact/async-loader') - : require.resolve('@preact/async-loader/legacy'); + const { isProd, source, src } = env; + const asyncLoader = require.resolve('@preact/async-loader'); let entry = { bundle: resolve(__dirname, './../entry'), diff --git a/packages/cli/package.json b/packages/cli/package.json index 17b20f0d4..9d792d1b4 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -53,8 +53,8 @@ }, "peerDependencies": { "less-loader": "^7.3.0", - "preact": "*", - "preact-render-to-string": "*", + "preact": "^10.0.0", + "preact-render-to-string": "^5.0.0", "sass-loader": "^10.2.0", "stylus-loader": "^4.3.3" }, diff --git a/packages/cli/tests/client.test.js b/packages/cli/tests/client.test.js index 67c2b47a5..07746b2a5 100644 --- a/packages/cli/tests/client.test.js +++ b/packages/cli/tests/client.test.js @@ -47,35 +47,6 @@ describe('client-side tests', () => { server.server.close(); }); - it('should hydrate routes progressively with preact8.', async () => { - let dir = await subject('progressive-hydration-preact8'); - await build(dir, {}, true); - const server = getServer(join(dir, 'build'), PORT); - - // let page = await loadPage(chrome, `http://127.0.0.1:${PORT}/`); - const page = await chrome.newPage(); - - page.on('console', consoleMessage => { - // eslint-disable-next-line - console[consoleMessage.type()](consoleMessage.text()); - }); - - await page.goto(`http://127.0.0.1:${PORT}/`); - - // await waitUntilExpression(page, `window.booted`); - await sleep(500); - - const mutations = await page.evaluate('window.ROOT_MUTATION_COUNT'); - - expect(mutations).toEqual(0); - - expect(await page.evaluate('window.CHANGED_VAR')).toEqual(undefined); - await page.click('button'); - expect(await page.evaluate('window.CHANGED_VAR')).toEqual(1); - - server.server.close(); - }); - it('should hydrate for pre-rendered URLs only', async () => { let dir = await subject('prerendering-hydration'); await build(dir, {}); diff --git a/packages/cli/tests/subjects/progressive-hydration-preact8/index.js b/packages/cli/tests/subjects/progressive-hydration-preact8/index.js deleted file mode 100644 index ed8f7111e..000000000 --- a/packages/cli/tests/subjects/progressive-hydration-preact8/index.js +++ /dev/null @@ -1,19 +0,0 @@ -import Home from './routes/home'; - -if (typeof window !== 'undefined') { - window.ROOT_MUTATION_COUNT = 0; - const root = document.querySelector('#app'); - const old = root.removeChild; - root.removeChild = child => { - window.ROOT_MUTATION_COUNT++; - old.call(this, child); - }; -} - -export default function App() { - return ( -
- -
- ); -} diff --git a/packages/cli/tests/subjects/progressive-hydration-preact8/package.json b/packages/cli/tests/subjects/progressive-hydration-preact8/package.json deleted file mode 100644 index f5ced7f6d..000000000 --- a/packages/cli/tests/subjects/progressive-hydration-preact8/package.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "private": true, - "name": "preact-prerender", - "dependencies": { - "preact": "8.5.3", - "preact-render-to-string": "4.1.0" - } -} diff --git a/packages/cli/tests/subjects/progressive-hydration-preact8/preact.config.js b/packages/cli/tests/subjects/progressive-hydration-preact8/preact.config.js deleted file mode 100644 index 35aadbdc8..000000000 --- a/packages/cli/tests/subjects/progressive-hydration-preact8/preact.config.js +++ /dev/null @@ -1,7 +0,0 @@ -module.exports = function (config) { - const modules = config.resolve.modules; - if (modules[0] === 'node_modules') { - modules.splice(0, 1); - modules.push('node_modules'); - } -}; diff --git a/packages/cli/tests/subjects/progressive-hydration-preact8/prerender-urls.json b/packages/cli/tests/subjects/progressive-hydration-preact8/prerender-urls.json deleted file mode 100644 index 7d52bcdaf..000000000 --- a/packages/cli/tests/subjects/progressive-hydration-preact8/prerender-urls.json +++ /dev/null @@ -1,15 +0,0 @@ -[ - { - "url": "/", - "title": "Home" - }, - { - "url": "/route66", - "title": "Route66" - }, - { - "url": "/custom", - "title": "Custom", - "myProp": "It worked!" - } -] diff --git a/packages/cli/tests/subjects/progressive-hydration-preact8/routes/home.js b/packages/cli/tests/subjects/progressive-hydration-preact8/routes/home.js deleted file mode 100644 index ec7699737..000000000 --- a/packages/cli/tests/subjects/progressive-hydration-preact8/routes/home.js +++ /dev/null @@ -1,12 +0,0 @@ -export default ({ url }) => ( -
- Home {url}{' '} - -
-);