@mcpjam/widget-react 0.1.16 → 0.1.17

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/dist/index.js CHANGED
@@ -1245,6 +1245,27 @@ function useInitialRenderOutcome(ready, failed, notify) {
1245
1245
  }
1246
1246
  }, [ready, failed, notify]);
1247
1247
  }
1248
+ function useSandboxProxyGeneration({
1249
+ bridgeTransportReady,
1250
+ hasWidgetHtml,
1251
+ logReady
1252
+ }) {
1253
+ const [generation, setGeneration] = useState(0);
1254
+ const bridgeTransportReadyRef = useRef(bridgeTransportReady);
1255
+ bridgeTransportReadyRef.current = bridgeTransportReady;
1256
+ const hasWidgetHtmlRef = useRef(hasWidgetHtml);
1257
+ hasWidgetHtmlRef.current = hasWidgetHtml;
1258
+ const logReadyRef = useRef(logReady);
1259
+ logReadyRef.current = logReady;
1260
+ const onReady = useCallback(() => {
1261
+ setGeneration((current) => current + 1);
1262
+ logReadyRef.current({
1263
+ bridgeTransportReady: bridgeTransportReadyRef.current,
1264
+ hasWidgetHtml: hasWidgetHtmlRef.current
1265
+ });
1266
+ }, []);
1267
+ return { generation, onReady };
1268
+ }
1248
1269
  var WidgetFullscreenPlacementContext = createContext(null);
1249
1270
  function McpAppsModal({
1250
1271
  open,
@@ -2509,7 +2530,6 @@ function MCPAppsRendererSurface({
2509
2530
  const [firstCspBlock, setFirstCspBlock] = useState(null);
2510
2531
  const [widgetHtml, setWidgetHtml] = useState(null);
2511
2532
  const [openInAppUrlOverride, setOpenInAppUrlOverride] = useState(null);
2512
- const [sandboxProxyReady, setSandboxProxyReady] = useState(false);
2513
2533
  const [viewMount, setViewMount] = useState(null);
2514
2534
  const [bridgeTransportReady, setBridgeTransportReady] = useState(false);
2515
2535
  const [bridgeGeneration, setBridgeGeneration] = useState(0);
@@ -3955,9 +3975,17 @@ function MCPAppsRendererSurface({
3955
3975
  hasOwnedMessage
3956
3976
  ]
3957
3977
  );
3978
+ const {
3979
+ generation: sandboxProxyGeneration,
3980
+ onReady: handleSandboxProxyReady
3981
+ } = useSandboxProxyGeneration({
3982
+ bridgeTransportReady,
3983
+ hasWidgetHtml,
3984
+ logReady: (details) => logWidgetDebug("ui-to-host", "debug/sandbox-proxy-ready", details)
3985
+ });
3958
3986
  useEffect(() => {
3959
3987
  if (!widgetHtml) return;
3960
- if (!sandboxProxyReady) {
3988
+ if (sandboxProxyGeneration === 0) {
3961
3989
  logWidgetDebug("host-to-ui", "debug/bridge-connect-skipped", {
3962
3990
  reason: "sandbox-proxy-not-ready"
3963
3991
  });
@@ -4096,7 +4124,8 @@ function MCPAppsRendererSurface({
4096
4124
  };
4097
4125
  }, [
4098
4126
  widgetHtml,
4099
- sandboxProxyReady,
4127
+ // A reloaded proxy is a new window with no view: reconnect to it.
4128
+ sandboxProxyGeneration,
4100
4129
  registerBridgeHandlers,
4101
4130
  refreshAppProvidedTools,
4102
4131
  // Bridge must rebuild when the resolved sandbox policy changes — a host
@@ -4521,13 +4550,7 @@ function MCPAppsRendererSurface({
4521
4550
  browserStorage: effectiveSandbox.browserStorage,
4522
4551
  colorScheme: resolvedTheme,
4523
4552
  recordMode,
4524
- onProxyReady: () => {
4525
- setSandboxProxyReady(true);
4526
- logWidgetDebug("ui-to-host", "debug/sandbox-proxy-ready", {
4527
- bridgeTransportReady,
4528
- hasWidgetHtml
4529
- });
4530
- },
4553
+ onProxyReady: handleSandboxProxyReady,
4531
4554
  onMessage: handleSandboxMessage,
4532
4555
  title: `MCP App: ${toolName}`,
4533
4556
  hostedMode: host.surface.hostedMode,