Skip to content

Commit 2611a1f

Browse files
committed
fix: stabilize complex-rubric esm loading and author sync output
Prevent sync from producing invalid `: any` assignment code in complex-rubric author output, harden local ESM module resolution, and extend matrix coverage for loader/registry import failures across elements. Made-with: Cursor
1 parent 1727215 commit 2611a1f

9 files changed

Lines changed: 70 additions & 25 deletions

File tree

apps/element-demo/scripts/generate-element-imports.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function packageSpecifier(
3636
entryPoint: 'delivery' | 'controller' | 'author' | 'print'
3737
): string {
3838
if (entryPoint === 'delivery') {
39-
return `@pie-element/${elementName}`;
39+
return `@pie-element/${elementName}/delivery`;
4040
}
4141
return `@pie-element/${elementName}/${entryPoint}`;
4242
}

apps/element-demo/test/e2e/smoke-matrix.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ const CRITICAL_CONSOLE_PATTERNS = [
3535
/window\.pie not found/i,
3636
/Module not found:/i,
3737
/Can't resolve/i,
38+
/Failed to resolve module specifier/i,
39+
/\[element-player\/demo\] Failed registry import/i,
40+
/\[element-loader\] Failed to load element/i,
3841
/Cannot update an unmounted root/i,
3942
];
4043

apps/element-demo/vite.config.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,22 @@ export default defineConfig({
118118
// Force Vite to use the main field (lib/index.js) instead
119119
'@pie-framework/math-validation': '@pie-framework/math-validation/lib/index.js',
120120
},
121+
// Keep a single ProseMirror instance across workspace packages.
122+
// Without this, mixed tiptap/prosemirror imports can register duplicate
123+
// selection IDs (e.g. gapcursor) and crash module evaluation.
124+
dedupe: [
125+
'@tiptap/pm',
126+
'prosemirror-state',
127+
'prosemirror-model',
128+
'prosemirror-view',
129+
'prosemirror-transform',
130+
'prosemirror-history',
131+
'prosemirror-commands',
132+
'prosemirror-keymap',
133+
'prosemirror-inputrules',
134+
'prosemirror-gapcursor',
135+
'prosemirror-schema-list',
136+
],
121137
},
122138

123139
server: {

bun.lock

Lines changed: 2 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/element-player/src/lib/element-loader.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,11 @@ async function resolveModule(
4444
const modulePath = request.cdnUrl
4545
? `${request.cdnUrl}/${request.packagePath}`
4646
: request.packagePath;
47-
return import(/* @vite-ignore */ modulePath);
47+
if (request.cdnUrl) {
48+
return import(/* @vite-ignore */ modulePath);
49+
}
50+
// Let Vite resolve local workspace specifiers in ESM mode.
51+
return import(modulePath);
4852
}
4953

5054
/**

packages/elements-react/complex-rubric/src/author/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import { ModelUpdatedEvent } from '@pie-element/shared-configure-events';
1212
import React from 'react';
1313
import { createRoot } from 'react-dom/client';
14-
import RubricConfigure from '@pie-element/rubric';
15-
import MultiTraitRubricConfigure from '@pie-element/multi-trait-rubric';
14+
import RubricConfigure from '@pie-element/rubric/author';
15+
import MultiTraitRubricConfigure from '@pie-element/multi-trait-rubric/author';
1616
import debug from 'debug';
1717
import { defaults } from 'lodash-es';
1818
import Main from './main.js';

packages/elements-react/complex-rubric/src/author/main.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ export class Main extends React.Component {
8888
switch (rubricType) {
8989
case RUBRIC_TYPES.SIMPLE_RUBRIC:
9090
default:
91-
rubricTag: any = (
91+
rubricTag = (
9292
<rubric-configure
9393
id="simpleRubric"
9494
key="simple-rubric"
@@ -104,7 +104,7 @@ export class Main extends React.Component {
104104
break;
105105

106106
case RUBRIC_TYPES.MULTI_TRAIT_RUBRIC:
107-
rubricTag: any = (
107+
rubricTag = (
108108
<multi-trait-rubric-configure
109109
id="multiTraitRubric"
110110
key="multi-trait-rubric"
@@ -121,7 +121,7 @@ export class Main extends React.Component {
121121
break;
122122

123123
case RUBRIC_TYPES.RUBRICLESS:
124-
rubricTag: any = (
124+
rubricTag = (
125125
<rubric-configure
126126
id="rubricless"
127127
key="rubricless"

tools/cli/src/lib/upstream/sync-imports.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -821,12 +821,11 @@ export function fixStyledComponentTypes(content: string): string {
821821
const constStyledRegex = /const (\w+) = styled\(/g;
822822
transformed = transformed.replace(constStyledRegex, 'const $1: any = styled(');
823823

824-
// Pattern 3: Class methods/arrow functions that might return styled components
825-
// Add `: any` return type to methods that are missing type annotations
826-
// Match: methodName = () => { or methodName = (params) => {
827-
// But only at start of line (class methods), not property assignments like reader.onload =
828-
// And only if they don't already have a type annotation
829-
const methodRegex = /^(\s*)(\w+)\s*=\s*\([^)]*\)\s*=>\s*\{/gm;
824+
// Pattern 3: Class field arrow functions that might return styled components
825+
// Add `: any` return type to class fields missing type annotations.
826+
// IMPORTANT: keep this line-scoped so we do not accidentally match multiline JSX
827+
// assignments such as `foo = (<Component ref={(r) => { ... }} />)`.
828+
const methodRegex = /^(\s*)(\w+)\s*=\s*\([^)\n]*\)\s*=>\s*\{/gm;
830829
transformed = transformed.replace(methodRegex, (match) => {
831830
// Check if already has type annotation (: type = )
832831
const hasTypeAnnotation = match.includes(':');

tools/cli/tests/transform-configure-lib-imports.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, expect, it } from 'vitest';
22
import {
3+
fixStyledComponentTypes,
34
transformConfigureUtilsImports,
45
transformLegacyConfigureLibImports,
56
transformSelfReferentialImports,
@@ -65,3 +66,35 @@ import { FractionModelChart } from '@pie-element/fraction-model';
6566
expect(output).toContain("from '../delivery/index.js'");
6667
});
6768
});
69+
70+
describe('fixStyledComponentTypes', () => {
71+
it('does not rewrite multiline JSX assignments that contain inline arrow functions', () => {
72+
const input = `
73+
class Main {
74+
onModelChanged = (model) => {
75+
return model;
76+
};
77+
78+
render() {
79+
let rubricTag = '';
80+
rubricTag = (
81+
<rubric-configure
82+
ref={(ref) => {
83+
if (ref) {
84+
this.simpleRubric = ref;
85+
}
86+
}}
87+
/>
88+
);
89+
return rubricTag;
90+
}
91+
}
92+
`;
93+
94+
const output = fixStyledComponentTypes(input);
95+
96+
expect(output).toContain('onModelChanged: any = (model) => {');
97+
expect(output).toContain('rubricTag = (');
98+
expect(output).not.toContain('rubricTag: any = (');
99+
});
100+
});

0 commit comments

Comments
 (0)