@marimo-team/frontend 0.24.1-dev13 → 0.24.1-dev18

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.
@@ -56,6 +56,19 @@ describe("CachePopover getCacheInfo throttling", () => {
56
56
  return () => act(() => dispose());
57
57
  }
58
58
 
59
+ it("renders content synchronously for CodeMirror's initial measurement", async () => {
60
+ const dom = document.createElement("div");
61
+
62
+ // Keep the mount outside `act()`. It would flush an asynchronous render
63
+ // and make this assertion pass without `flushSync`.
64
+ const dispose = mountLensPopover(dom, CACHE_SPEC);
65
+
66
+ expect(dom.textContent).toContain("my_cache");
67
+ await act(async () => {
68
+ dispose();
69
+ });
70
+ });
71
+
59
72
  it("does not refetch on every hover, only after the throttle interval elapses", () => {
60
73
  const disposeFirst = mount();
61
74
  expect(getCacheInfoMock).toHaveBeenCalledTimes(1);
@@ -4,6 +4,7 @@ import { Provider, useAtomValue } from "jotai";
4
4
  import { DatabaseZapIcon } from "lucide-react";
5
5
  import type React from "react";
6
6
  import { useEffect } from "react";
7
+ import { flushSync } from "react-dom";
7
8
  import { createRoot } from "react-dom/client";
8
9
  import { useLocale } from "react-aria";
9
10
  import { ProtocolIcon } from "@/components/storage/components";
@@ -39,11 +40,16 @@ export function mountLensPopover(
39
40
  spec: CodeLensSpec,
40
41
  ): () => void {
41
42
  const root = createRoot(dom);
42
- root.render(
43
- <Provider store={store}>
44
- <LensPopover spec={spec} />
45
- </Provider>,
46
- );
43
+ // CodeMirror measures and positions the tooltip as soon as this function
44
+ // returns. Render now so it measures the popover content, not an empty
45
+ // container that later grows over the hovered icon.
46
+ flushSync(() => {
47
+ root.render(
48
+ <Provider store={store}>
49
+ <LensPopover spec={spec} />
50
+ </Provider>,
51
+ );
52
+ });
47
53
  // Defer so tearing the tooltip down from inside a React event (e.g. the
48
54
  // icon's click handler) doesn't unmount mid-render
49
55
  return () => queueMicrotask(() => root.unmount());