⚛️ Add Suspense and ErrorBoundary examples#70
⚛️ Add Suspense and ErrorBoundary examples#70DAreRodz merged 3 commits intomain-full-vdom-hydrationfrom
Suspense and ErrorBoundary examples#70Conversation
src/blocks/interactive-child/view.js
Outdated
| <Suspense | ||
| fallback={ | ||
| <p key="suspense"> | ||
| <div>Loading...</div> | ||
| </p> | ||
| } | ||
| > |
There was a problem hiding this comment.
This Suspense wrapper needs to be on the parent block. Otherwise, we are only testing that it works in Preact, aren't we? 😄
There was a problem hiding this comment.
Sure, sure! This is just the first step, which is still not working. 😅
I switched the PR back to a draft.
src/blocks/interactive-child/view.js
Outdated
| </p> | ||
| } | ||
| > | ||
| <div key="suspense"> |
There was a problem hiding this comment.
Why do you need the key? Is it a Suspense thing?
There was a problem hiding this comment.
It's not, I was just testing if I can make Suspense hydration work (see #70 (comment)).
I noticed that even if key could fix the error by making Preact recognize the elements and overwriting it, as key is not serialized during save(), this is not a valid approach.
There was a problem hiding this comment.
We can use wp-key if necessary and then switch to key in the toVdom (or options.vnode).
Let me know if that helps because I was even thinking that it should be wp-key to make everything related to this hydration prefixed with wp-.
There was a problem hiding this comment.
Yes, I was just thinking of using a directive for that. Let me try it.
|
Note here for the future: we need to figure out how this would work with out-of-order hydration. |
|
I'm afraid the Let's say we render the fallback during So, this JSX <Suspense fallback={<div>Loading...</div>}>
<LazyParagraph>Hello!</LazyParagraph>
</Suspense>produces this HTML. <div>Loading...</div>Then, when
Surprisingly, the fallback is preserved in both cases when <p>Hello!</p>
<div>Loading...</div>I'll look deeper later to see if we can make this work. |
|
It turns out that It does, though, if |
|
I've tested this in isolation, and even though I can't make Suspense work with I'm not sure what we are doing differently here. |
Suspense and ErrorBoundary examplesSuspense and ErrorBoundary examples
|
I'm not sure if I'm doing something wrong, but in isolation, I'm not getting the same behavior with Preact's |
|
@DAreRodz and I were able to reproduce the same behavior on Preact, so it's not something we are doing wrong: https://stackblitz.com/edit/vitejs-vite-r6rhtx?file=src%2Fmain.jsx It looks like |
This reverts commit 28d5543.
|
I've removed the |

I've added two simple examples to check if
SuspenseanduseErrorBoundarywork out of the box. Using contexts was already tested, and it works fine, without any problems.To test error boundaries, I did the following: ✅
useErrorBoundaryhook inside Interactive Parent to render a fallback when an error reaches the component. The fallback shows a button to recover from the error.To test
Suspense, I added a lazy-loaded component that renders inside Interactive Child. 🚧