zudoku 0.3.0-dev.74 → 0.3.0-dev.75

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zudoku",
3
- "version": "0.3.0-dev.74",
3
+ "version": "0.3.0-dev.75",
4
4
  "type": "module",
5
5
  "files": [
6
6
  "dist",
@@ -55,6 +55,4 @@ export function Callback({
55
55
  </div>
56
56
  );
57
57
  }
58
-
59
- return <div>Loading...</div>;
60
58
  }
@@ -8,6 +8,7 @@ import {
8
8
  useContext,
9
9
  useEffect,
10
10
  useMemo,
11
+ useRef,
11
12
  useState,
12
13
  } from "react";
13
14
  import { ErrorBoundary } from "react-error-boundary";
@@ -52,8 +53,10 @@ const DevPortalInner = ({
52
53
  () => ({ ...MdxComponents, ...props.mdx?.components }),
53
54
  [props.mdx?.components],
54
55
  );
56
+ const [isInitialized, setIsInitialized] = useState(false);
55
57
  const { stagger } = useContext(StaggeredRenderContext);
56
58
  const [didNavigate, setDidNavigate] = useState(false);
59
+ const initRef = useRef<"idle" | "pending" | "done">("idle");
57
60
  const staggeredValue = useMemo(
58
61
  () => (didNavigate ? { stagger: true } : { stagger }),
59
62
  [stagger, didNavigate],
@@ -69,11 +72,25 @@ const DevPortalInner = ({
69
72
 
70
73
  const [devPortalContext] = useState(() => new DevPortalContext(props));
71
74
 
75
+ // TODO could be handled more elegantly
76
+ useEffect(() => {
77
+ if (initRef.current === "pending") return;
78
+ initRef.current = "pending";
79
+ void devPortalContext.initialize().then(() => {
80
+ initRef.current = "done";
81
+ setIsInitialized(true);
82
+ });
83
+ }, [devPortalContext]);
84
+
72
85
  const heads = props.plugins
73
86
  ?.filter(hasHead)
74
87
  // eslint-disable-next-line react/no-array-index-key
75
88
  .map((plugin, i) => <Fragment key={i}>{plugin.getHead?.()}</Fragment>);
76
89
 
90
+ if (!isInitialized) {
91
+ return null;
92
+ }
93
+
77
94
  return (
78
95
  <QueryClientProvider client={queryClient}>
79
96
  <Helmet>{heads}</Helmet>
@@ -113,16 +113,14 @@ export class DevPortalContext {
113
113
  this.authentication = config.authentication;
114
114
  this.meta = config.metadata;
115
115
  this.page = config.page;
116
-
117
- void this.initialize();
118
116
  }
119
117
 
120
118
  initialize = async () => {
121
- await Promise.all([
119
+ await Promise.all(
122
120
  this.plugins
123
121
  .filter(needsInitialization)
124
122
  .map((plugin) => plugin.initialize?.(this)),
125
- ]);
123
+ );
126
124
  };
127
125
 
128
126
  invalidateCache = async (key: DevPortalCacheKey[]) => {