Skip to content

Commit b1ad20e

Browse files
committed
fix: share one Svelte runtime across built components and fix CodeHighlighter language loading
- share the Svelte runtime of ms.Application with every other component in the bridge generation build (Gradio >= 6.9), so cross-component `$state` props are tracked again (revisited tabs / menus switch back, AutoLoading shows up) - statically map the Prism languages that antdx.CodeHighlighter imports through a bare template `import()` - share `@ant-design/x` through `window.ms_globals` (wrong `antdx` key) - split `frontend/plugin.js` into `frontend/plugins/`, and read the shared globals from `inject.ts` instead of a hand-written table
1 parent 0af186b commit b1ad20e

13 files changed

Lines changed: 712 additions & 245 deletions
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@modelscope-studio/frontend': patch
3+
'modelscope_studio': patch
4+
---
5+
6+
fix: `antdx.CodeHighlighter` fails to load Prism languages (`Failed to resolve module specifier`) and renders code without highlighting in the production build

‎.changeset/share-ant-design-x.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@modelscope-studio/frontend': patch
3+
'modelscope_studio': patch
4+
---
5+
6+
fix: share `@ant-design/x` across components instead of bundling a copy into each of them

‎.changeset/share-svelte-runtime.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@modelscope-studio/frontend': patch
3+
'modelscope_studio': patch
4+
---
5+
6+
fix: components stop updating after the first render in the production build, e.g. revisited tabs or menu items no longer switch the content and `ms.AutoLoading` no longer shows up

‎frontend/defineConfig.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import react from '@vitejs/plugin-react';
22

3-
import { ModelScopeStudioVitePlugin } from './plugin.js';
3+
import { ModelScopeStudioVitePlugin } from './plugins/index.js';
44

55
/**
66
* @type {(options:{ external?: boolean | { excludes:string[] } }) => any}

‎frontend/fixtures.d.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ declare module 'virtual:component-loader' {
22
export const load_component;
33
}
44

5+
declare module 'virtual:ms-svelte-runtime' {}
6+
57
declare module '*?worker' {
68
const workerConstructor: {
79
new (options?: { name?: string }): Worker;

‎frontend/plugin.js‎

Lines changed: 0 additions & 243 deletions
This file was deleted.

‎frontend/plugins/config.js‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import path from 'node:path';
2+
import url from 'node:url';
3+
4+
const frontendDir = path.resolve(
5+
path.dirname(url.fileURLToPath(import.meta.url)),
6+
'..'
7+
);
8+
9+
/**
10+
* The source aliases (keep in sync with `paths` of the root `tsconfig.json`)
11+
* and the production mode of the build.
12+
*
13+
* @type {() => import('vite').Plugin}
14+
*/
15+
export function configPlugin() {
16+
return {
17+
name: 'modelscope-studio-config',
18+
config(userConfig, { command }) {
19+
if (command === 'build') {
20+
userConfig.define = {
21+
...userConfig.define,
22+
'process.env.NODE_ENV': JSON.stringify('production'),
23+
};
24+
userConfig.build ??= {};
25+
}
26+
27+
userConfig.resolve ??= {};
28+
userConfig.resolve.alias = {
29+
...(userConfig.resolve.alias || {}),
30+
'@utils': path.resolve(frontendDir, 'utils'),
31+
'@globals': path.resolve(frontendDir, 'globals'),
32+
'@svelte-preprocess-react': path.resolve(
33+
frontendDir,
34+
'svelte-preprocess-react'
35+
),
36+
};
37+
},
38+
};
39+
}

0 commit comments

Comments
 (0)