Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions runner/apps/authoring/src/theme/codegen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -186,15 +186,22 @@ function wireTheme(files: Record<string, string>): WireTarget | null {
// 1. JSX/Vue wrapper element. Replace an existing theme prop rather than
// adding a second one — several starters already set their own.
if (/<(HotTable|hot-table)\b/.test(source)) {
next = /\btheme=\{[^}]*\}/.test(source)
const withTheme = /\btheme=\{[^}]*\}/.test(source)
? source.replace(/\btheme=\{[^}]*\}/, "theme={customTheme}")
: source.replace(/<(HotTable|hot-table)\b/, "<$1 theme={customTheme}");
// `theme` and `themeName` are aliases and Handsontable refuses to take
// both — it warns and drops themeName. Leaving the dead prop behind
// means every themed demo logs a warning it cannot act on, so the one
// being replaced goes.
next = stripThemeName(withTheme);
} else if (/new Handsontable\(\s*[A-Za-z_$][\w$]*\s*,\s*\{/.test(source)) {
// 2. Vanilla settings object.
next = source.replace(/(new Handsontable\(\s*[A-Za-z_$][\w$]*\s*,\s*\{)/, "$1\n theme: customTheme,");
next = stripThemeName(
source.replace(/(new Handsontable\(\s*[A-Za-z_$][\w$]*\s*,\s*\{)/, "$1\n theme: customTheme,"),
);
} else if (/gridSettings[^=]*=\s*\{/.test(source)) {
// 3. Angular's settings object.
next = source.replace(/(gridSettings[^=]*=\s*\{)/, "$1\n theme: customTheme,");
next = stripThemeName(source.replace(/(gridSettings[^=]*=\s*\{)/, "$1\n theme: customTheme,"));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reset cannot restore themeName

Medium Severity

Wiring now permanently deletes the original themeName from the demo source. Reset only removes the customTheme import and theme wiring, so it cannot put themeName back. After Apply then Reset, demos that relied on an explicit themeName stay without it in the editable and downloadable code.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 0e3b079. Configure here.

}

if (!next) continue;
Expand All @@ -208,6 +215,14 @@ function wireTheme(files: Record<string, string>): WireTarget | null {
return null;
}

/** Remove a `themeName` prop or setting: it is an alias of `theme`, and
* Handsontable warns and ignores it when both are present. */
function stripThemeName(source: string): string {
return source
.replace(/\n?[^\n]*\bthemeName\s*=\s*["'][^"']*["'][^\n]*/g, "")
.replace(/\n?[^\n]*\bthemeName\s*:\s*["'][^"']*["'],?[^\n]*/g, "");
}

/** Does the example look like TypeScript? Decides the module's extension. */
function isTypescript(files: Record<string, string>): boolean {
return Object.keys(files).some((p) => /\.tsx?$/.test(p));
Expand Down
Loading