Skip to content

Commit

Permalink
fix: async loader missing undefined check (#1763)
Browse files Browse the repository at this point in the history
* fix: Bail from `getPreviousSibling` if VNode undefined

Co-authored-by: psabharwal123 <puneet.sabharwal@hotmail.com>
Co-authored-by: Sparrowhawk <sparrowhawk-ea@hotmail.com>

* docs: Adding changeset

* test: Update build hashes

Co-authored-by: psabharwal123 <puneet.sabharwal@hotmail.com>
Co-authored-by: Sparrowhawk <sparrowhawk-ea@hotmail.com>
  • Loading branch information
3 people authored Dec 23, 2022
1 parent fb100b3 commit 3c371f7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/odd-cups-invent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@preact/async-loader': patch
---

Fix for possible type error in `async-loader`
4 changes: 2 additions & 2 deletions packages/async-loader/async.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const PENDING = {};
// Given a VNode, finds its previous element sibling
function getPreviousSibling(vnode, inner) {
// in an element parent with no preceeding siblings means we're the first child
if (typeof vnode.type === 'string') return null;
if (!vnode || typeof vnode.type === 'string') return null;
const parent = vnode.__;
if (!parent) return;
let children = parent.__k;
Expand All @@ -16,7 +16,7 @@ function getPreviousSibling(vnode, inner) {
if (end === -1) end = children.length;
for (let i = end; i--; ) {
const child = children[i];
const dom = (child && child.__e) || getPreviousSibling(child, true);
const dom = child && (child.__e || getPreviousSibling(child, true));
if (dom) return dom;
}
}
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/tests/images/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ exports.default = Object.assign({}, common, {
'ssr-build/ssr-bundle.js.map': 52686,
'ssr-build/asset-manifest.json': 178,
'bundle.259c5.css': 901,
'bundle.f79fb.js': 21429,
'bundle.f79fb.js.map': 111801,
'bundle.85124.js': 21429,
'bundle.85124.js.map': 111801,
'favicon.ico': 15086,
'index.html': 2034,
'manifest.json': 455,
Expand Down

0 comments on commit 3c371f7

Please sign in to comment.