Skip to content

Commit

Permalink
refactor: Swap out fake suspense impl
Browse files Browse the repository at this point in the history
  • Loading branch information
rschristian committed Apr 9, 2024
1 parent f2b6239 commit 84c1f42
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 12 deletions.
7 changes: 4 additions & 3 deletions src/components/code-block/index.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useMemo } from 'preact/hooks';
import { Suspense } from 'preact/compat';
import { wrap } from 'comlink';
import { FakeSuspense, useResource } from '../../lib/use-resource';
import { useResource } from '../../lib/use-resource';

let prismWorker;

Expand Down Expand Up @@ -75,9 +76,9 @@ function HighlightedCodeBlock({ code, lang }) {
return (
<div class="highlight-container">
<pre class="highlight">
<FakeSuspense fallback={fallback}>
<Suspense fallback={fallback}>
<HighlightedCode code={code} lang={lang} />
</FakeSuspense>
</Suspense>
</pre>
{repl && (
<a class="repl-link" href={`/repl?code=${encodeURIComponent(source)}`}>
Expand Down
9 changes: 0 additions & 9 deletions src/lib/use-resource.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,3 @@ export function useResource(fn, deps) {
else if (state.status === 'error') throw state.result;
throw state.promise;
}

export function FakeSuspense(props) {
this.__c = childDidSuspend;
return this.state && this.state.suspended ? props.fallback : props.children;
}

function childDidSuspend(err) {
err.then(() => this.forceUpdate());
}

0 comments on commit 84c1f42

Please sign in to comment.