Skip to content

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.

Fix: ui.datetime() rendering with empty initial value (#3249)

devin-ai-integration[bot]3b9cba14df6e
diff --git a/frontend/src/components/data-table/__tests__/data-table.test.tsx b/frontend/src/components/data-table/__tests__/data-table.test.tsx
index 6e78d53db0..0a21eb0208 100644
--- a/frontend/src/components/data-table/__tests__/data-table.test.tsx
+++ b/frontend/src/components/data-table/__tests__/data-table.test.tsx
@@ -1,3 +1,4 @@
+/* Copyright 2024 Marimo. All rights reserved. */
import { render } from "@testing-library/react";
import { DataTable } from "../data-table";
import { describe, expect, it } from "vitest";
diff --git a/frontend/src/css/md.css b/frontend/src/css/md.css
index 9b249b6352..0312d0f788 100644
--- a/frontend/src/css/md.css
+++ b/frontend/src/css/md.css
@@ -178,8 +178,8 @@ button .prose.prose {
.prose .critic {
font-family: inherit;
- -webkit-border-radius: 3px;
- -moz-border-radius: 3px;
+ border-radius: 3px;
+ border-radius: 3px;
border-radius: 3px;
border-style: solid;
border-width: 1px;
@@ -188,18 +188,19 @@ button .prose.prose {
text-decoration: none;
}
-.prose .critic:before,
-.prose .critic:after {
+.prose .critic::before,
+.prose .critic::after {
content: "\00a0";
padding-top: 0.1rem;
padding-bottom: 0.1rem;
font-size: initial;
}
-.prose .block:before,
-.prose .block:after {
+.prose .block::before,
+.prose .block::after {
content: "";
}
+
.prose mark.critic {
border-color: var(--orange-9);
background: var(--orange-3);
@@ -221,11 +222,11 @@ button .prose.prose {
border: none;
}
-.prose ins.break:before,
-.prose del.break:before {
+.prose ins.break::before,
+.prose del.break::before {
content: "\00a0\b6\00a0";
- -webkit-border-radius: 3px;
- -moz-border-radius: 3px;
+ border-radius: 3px;
+ border-radius: 3px;
border-radius: 3px;
}
@@ -234,13 +235,13 @@ button .prose.prose {
content: "";
}
-.prose ins.break:before {
+.prose ins.break::before {
color: var(--green-9);
border: 1px solid var(--green-9);
background: var(--green-3);
}
-.prose del.break:before {
+.prose del.break::before {
color: var(--red-9);
border: 1px solid var(--red-9);
background: var(--red-3);
@@ -253,32 +254,32 @@ button .prose.prose {
border-bottom: 1px solid var(--blue-9);
}
-.prose span.critic:before,
-.prose span.critic:after {
+.prose span.critic::before,
+.prose span.critic::after {
font-size: inherit;
background: var(--blue-3);
border: 1px solid var(--blue-9);
}
-.prose span.critic:before {
+.prose span.critic::before {
content: "\00a0\bb";
border-right: none;
- -webkit-border-top-left-radius: 3px;
- -moz-border-top-left-radius: 3px;
border-top-left-radius: 3px;
- -webkit-border-bottom-left-radius: 3px;
- -moz-border-bottom-left-radius: 3px;
+ border-top-left-radius: 3px;
+ border-top-left-radius: 3px;
+ border-bottom-left-radius: 3px;
+ border-bottom-left-radius: 3px;
border-bottom-left-radius: 3px;
}
-.prose span.critic:after {
+.prose span.critic::after {
content: "\ab\00a0";
border-left: none;
- -webkit-border-top-right-radius: 3px;
- -moz-border-top-right-radius: 3px;
border-top-right-radius: 3px;
- -webkit-border-bottom-right-radius: 3px;
- -moz-border-bottom-right-radius: 3px;
+ border-top-right-radius: 3px;
+ border-top-right-radius: 3px;
+ border-bottom-right-radius: 3px;
+ border-bottom-right-radius: 3px;
border-bottom-right-radius: 3px;
}
diff --git a/frontend/src/hooks/__tests__/useBoolean.test.tsx b/frontend/src/hooks/__tests__/useBoolean.test.tsx
index 9723bf97b4..432ef8a10b 100644
--- a/frontend/src/hooks/__tests__/useBoolean.test.tsx
+++ b/frontend/src/hooks/__tests__/useBoolean.test.tsx
@@ -1,3 +1,4 @@
+/* Copyright 2024 Marimo. All rights reserved. */
import { expect, describe, it, vi } from "vitest";
import { renderHook, act } from "@testing-library/react";
import { useBoolean } from "../useBoolean";
diff --git a/frontend/src/hooks/__tests__/useDebounce.test.tsx b/frontend/src/hooks/__tests__/useDebounce.test.tsx
index 5b368d7207..8f23859202 100644
--- a/frontend/src/hooks/__tests__/useDebounce.test.tsx
+++ b/frontend/src/hooks/__tests__/useDebounce.test.tsx
@@ -1,3 +1,4 @@
+/* Copyright 2024 Marimo. All rights reserved. */
import { expect, describe, it, vi, beforeEach, afterEach } from "vitest";
import { renderHook, act } from "@testing-library/react";
import { useDebounce, useDebounceControlledState } from "../useDebounce";
diff --git a/frontend/src/hooks/__tests__/useEffectSkipFirstRender.test.tsx b/frontend/src/hooks/__tests__/useEffectSkipFirstRender.test.tsx
index e6c876d797..7819e0fb10 100644
--- a/frontend/src/hooks/__tests__/useEffectSkipFirstRender.test.tsx
+++ b/frontend/src/hooks/__tests__/useEffectSkipFirstRender.test.tsx
@@ -1,3 +1,4 @@
+/* Copyright 2024 Marimo. All rights reserved. */
import { renderHook } from "@testing-library/react";
import { describe, expect, it, vi } from "vitest";
import { useEffectSkipFirstRender } from "../useEffectSkipFirstRender";
diff --git a/frontend/src/hooks/__tests__/useInterval.test.tsx b/frontend/src/hooks/__tests__/useInterval.test.tsx
index fd439cac83..13d97df931 100644
--- a/frontend/src/hooks/__tests__/useInterval.test.tsx
+++ b/frontend/src/hooks/__tests__/useInterval.test.tsx
@@ -1,3 +1,4 @@
+/* Copyright 2024 Marimo. All rights reserved. */
import { expect, describe, it, vi, beforeEach, afterEach } from "vitest";
import { renderHook } from "@testing-library/react";
import { useInterval } from "../useInterval";
diff --git a/frontend/src/hooks/__tests__/useTimer.test.tsx b/frontend/src/hooks/__tests__/useTimer.test.tsx
index 14b0883dce..5bffc4fbae 100644
--- a/frontend/src/hooks/__tests__/useTimer.test.tsx
+++ b/frontend/src/hooks/__tests__/useTimer.test.tsx
@@ -1,3 +1,4 @@
+/* Copyright 2024 Marimo. All rights reserved. */
import { expect, describe, it, vi, beforeEach, afterEach } from "vitest";
import { renderHook, act } from "@testing-library/react";
import { useTimer } from "../useTimer";
diff --git a/frontend/src/hooks/useEffectSkipFirstRender.ts b/frontend/src/hooks/useEffectSkipFirstRender.ts
index 4286bf67c9..ce833f1cba 100644
--- a/frontend/src/hooks/useEffectSkipFirstRender.ts
+++ b/frontend/src/hooks/useEffectSkipFirstRender.ts
@@ -1,3 +1,4 @@
+/* Copyright 2024 Marimo. All rights reserved. */
import { useEffect, useRef } from "react";
/**
diff --git a/frontend/src/plugins/impl/DateTimePickerPlugin.tsx b/frontend/src/plugins/impl/DateTimePickerPlugin.tsx
index 2d607bd279..0ac2a55f39 100644
--- a/frontend/src/plugins/impl/DateTimePickerPlugin.tsx
+++ b/frontend/src/plugins/impl/DateTimePickerPlugin.tsx
@@ -54,11 +54,14 @@ const DateTimePickerComponent = (props: DateTimePickerProps): JSX.Element => {
props.setValue(isoStr);
};
+ // Add null check and default to undefined when no value is provided
+ const parsedValue = props.value ? parseDateTime(props.value) : undefined;
+
return (
<Labeled label={props.label} fullWidth={props.fullWidth}>
<DatePicker
granularity="minute"
- value={parseDateTime(props.value)}
+ value={parsedValue}
onChange={handleInput}
aria-label={props.label ?? "date time picker"}
minValue={parseDateTime(props.start)}
diff --git a/frontend/src/plugins/impl/__tests__/DateTimePickerPlugin.test.tsx b/frontend/src/plugins/impl/__tests__/DateTimePickerPlugin.test.tsx
new file mode 100644
index 0000000000..517c70d8ec
--- /dev/null
+++ b/frontend/src/plugins/impl/__tests__/DateTimePickerPlugin.test.tsx
@@ -0,0 +1,44 @@
+/* Copyright 2024 Marimo. All rights reserved. */
+import { DateTimePickerPlugin } from "../DateTimePickerPlugin";
+import { render } from "@testing-library/react";
+import { expect, describe, it } from "vitest";
+import type { IPluginProps } from "../../types";
+
+interface DateTimeData {
+ label: string | null;
+ start: string;
+ stop: string;
+ fullWidth: boolean;
+}
+
+describe("DateTimePickerPlugin", () => {
+ it("should render when initial value is not provided", () => {
+ const plugin = new DateTimePickerPlugin();
+ // Create a host element as required by IPluginProps
+ const host = document.createElement("div");
+ const props: IPluginProps<string, DateTimeData> = {
+ host,
+ value: "", // Empty string instead of undefined since type T = string
+ setValue: (valueOrFn) => {
+ // No-op function to satisfy lint requirements
+ if (typeof valueOrFn === "function") {
+ valueOrFn("");
+ }
+ },
+ data: {
+ label: null,
+ start: "2024-01-01T00:00:00",
+ stop: "2024-12-31T23:59:59",
+ fullWidth: false,
+ },
+ functions: {},
+ };
+ const { container } = render(plugin.render(props));
+
+ // Check if the component renders at all
+ expect(container.innerHTML).not.toBe("");
+ // Check for the date picker group
+ const datePicker = container.querySelector('[class*="group"]');
+ expect(datePicker).not.toBeNull();
+ });
+});