A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
fix: mo.ui.table does not render in HTML export on Windows Chrome/Edge (#3240)
Myles Scolnick8e78743458a4
diff --git a/frontend/src/core/static/__tests__/files.test.ts b/frontend/src/core/static/__tests__/files.test.tsindex 2a7b0802fe..eeb2567431 100644--- a/frontend/src/core/static/__tests__/files.test.ts+++ b/frontend/src/core/static/__tests__/files.test.ts@@ -60,6 +60,28 @@ describe("patchFetch", () => {);expect(text).toBe("Remote content");});++ it("should handle @file/ URLs and set content type", async () => {+ const virtualFiles = {+ "/@file/data.csv":+ "data:text/csv;base64,aGVsbG8sd29ybGQK" as DataURLString,+ };++ patchFetch(virtualFiles);++ // Test with both formats of @file URLs+ const responses = await Promise.all([+ window.fetch("/@file/data.csv"),+ window.fetch("./@file/data.csv"),+ window.fetch("http://example.com/@file/data.csv"),+ ]);++ for (const response of responses) {+ expect(response.headers.get("Content-Type")).toBe("text/csv");+ const text = await response.text();+ expect(text).toBe("hello,world\n");+ }+ });});describe("patchVegaLoader", () => {diff --git a/frontend/src/core/static/files.ts b/frontend/src/core/static/files.tsindex 8e7dee95b2..b9dc9030e4 100644--- a/frontend/src/core/static/files.ts+++ b/frontend/src/core/static/files.ts@@ -1,9 +1,8 @@/* Copyright 2024 Marimo. All rights reserved. */import type { StaticVirtualFiles } from "./types";-import { deserializeBlob } from "@/utils/blob";import { getStaticVirtualFiles } from "./static-state";-import type { DataURLString } from "@/utils/json/base64";+import { Logger } from "@/utils/Logger";/*** Patch fetch to resolve virtual files@@ -19,20 +18,36 @@ export function patchFetch(// eslint-disable-next-line @typescript-eslint/no-base-to-stringconst urlString = input instanceof Request ? input.url : input.toString();- const url =- urlString.startsWith("/") || urlString.startsWith("./")- ? new URL(urlString, window.location.origin)- : new URL(urlString);-- if (files[url.pathname]) {- const base64 = files[url.pathname];- const blob = await deserializeBlob(base64);- return new Response(blob);+ if (urlString.startsWith("data:")) {+ return originalFetch(input, init);}- // Fallback to the original fetch- // eslint-disable-next-line @typescript-eslint/no-explicit-any- return (originalFetch as any)(input, init);+ try {+ const url =+ urlString.startsWith("/") || urlString.startsWith("./")+ ? new URL(urlString, window.location.origin)+ : new URL(urlString);++ const filePath = url.pathname;+ if (files[filePath]) {+ const base64 = files[filePath];+ // Convert data URL to blob+ const response = await originalFetch(base64);+ const blob = await response.blob();+ return new Response(blob, {+ headers: {+ "Content-Type": getContentType(filePath),+ },+ });+ }++ // Fallback to the original fetch+ return originalFetch(input, init);+ } catch (error) {+ Logger.error("Error parsing URL", error);+ // If the URL is invalid, just fallback to the original fetch+ return originalFetch(input, init);+ }};return () => {@@ -40,6 +55,20 @@ export function patchFetch(};}+function getContentType(fileName: string): string {+ if (fileName.endsWith(".csv")) {+ return "text/csv";+ }+ if (fileName.endsWith(".json")) {+ return "application/json";+ }+ if (fileName.endsWith(".txt")) {+ return "text/plain";+ }+ // Default to octet-stream if unknown+ return "application/octet-stream";+}+export function patchVegaLoader(loader: {http: (url: string) => Promise<string>;@@ -52,8 +81,7 @@ export function patchVegaLoader(const pathname = new URL(url, document.baseURI).pathname;if (files[url] || files[pathname]) {const base64 = files[url] || files[pathname];- const blob = await deserializeBlob(base64);- return blob.text();+ return await window.fetch(base64).then((r) => r.text());}try {@@ -61,9 +89,7 @@ export function patchVegaLoader(} catch (error) {// If its a data URL, just return the dataif (url.startsWith("data:")) {- return deserializeBlob(url as DataURLString).then((blob) =>- blob.text(),- );+ return await window.fetch(url).then((r) => r.text());}// Re-throw the errorthrow error;