Skip to content

Commit e275a32

Browse files
committed
Update packages & fix extension loading bug with CDN
1 parent f4b2f91 commit e275a32

File tree

9 files changed

+75
-86
lines changed

9 files changed

+75
-86
lines changed

mobile/android/app/src/main/AndroidManifest.xml

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
<?xml version="1.0" encoding="utf-8" ?>
1+
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
33
<application
44
android:allowBackup="true"
55
android:icon="@mipmap/ic_launcher"
66
android:label="@string/app_name"
77
android:roundIcon="@mipmap/ic_launcher_round"
88
android:supportsRtl="true"
9-
android:theme="@style/AppTheme">
9+
android:theme="@style/AppTheme"
10+
android:networkSecurityConfig="@xml/network_security_config"
11+
>
1012
<activity
1113
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode"
1214
android:name=".MainActivity"
@@ -25,7 +27,8 @@
2527
android:authorities="${applicationId}.fileprovider"
2628
android:exported="false"
2729
android:grantUriPermissions="true">
28-
<meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths" />
30+
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
31+
android:resource="@xml/file_paths" />
2932
</provider>
3033
</application>
3134

@@ -39,4 +42,4 @@
3942
<!-- Storage -->
4043
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
4144
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
42-
</manifest>
45+
</manifest>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<network-security-config>
3+
<domain-config cleartextTrafficPermitted="true">
4+
<domain includeSubdomains="true">localhost</domain>
5+
</domain-config>
6+
</network-security-config>

package-lock.json

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

web/components/misc/extension-loader.tsx

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useEffect, useRef } from "react";
22
import { createRoot, Root } from "react-dom/client";
3-
import { loadRemote, preloadRemote } from "@module-federation/runtime";
3+
import { loadRemote } from "@module-federation/runtime";
44
import React from "react";
55

66
export default function ExtensionLoader({
@@ -16,7 +16,7 @@ export default function ExtensionLoader({
1616
const rootRef = useRef<Root | null>(null);
1717

1818
useEffect(() => {
19-
function renderExtension(LoadedExtension: any) {
19+
async function renderExtension(LoadedExtension: any) {
2020
if (iframeRef.current) {
2121
const iframe = iframeRef.current;
2222
const iframeDoc = iframe.contentWindow?.document;
@@ -29,10 +29,25 @@ export default function ExtensionLoader({
2929
const root = createRoot(rootElement, {});
3030
rootRef.current = root;
3131
// Inject extension global styles into iframe
32-
const link = iframeDoc.createElement("link");
33-
link.rel = "stylesheet";
34-
link.href = `${remoteOrigin}/${moduleId}/${moduleVersion}/__federation_expose_main.globals.css`;
35-
iframeDoc.head.appendChild(link);
32+
// not always named this, especially in production build
33+
34+
const manifestUri = `${remoteOrigin}/${moduleId}/${moduleVersion}/mf-manifest.json`;
35+
const manifest = await fetch(manifestUri).then((res) => res.json());
36+
console.log("Manifest", manifest);
37+
const cssFiles = manifest.exposes[0].assets.css.sync as string[];
38+
39+
for (const cssFile of cssFiles) {
40+
if (cssFile.endsWith(".css")) {
41+
// Need to make sure CDN returns the correct MIME type for CSS files (e.g. text/css);
42+
// otherwise, the CSS file will not be loaded in the iframe.
43+
// On local dev server, webpack dev handles MIME types automatically, so this is not an issue.
44+
const link = iframeDoc.createElement("link");
45+
link.rel = "stylesheet";
46+
link.href = `${remoteOrigin}/${moduleId}/${moduleVersion}/${cssFile}`;
47+
iframeDoc.head.appendChild(link);
48+
}
49+
}
50+
3651
root.render(<LoadedExtension />);
3752
}
3853
}

web/components/misc/icon.tsx

Lines changed: 14 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"use client";
22

33
import { useTheme } from "next-themes";
4-
import Image from "next/image";
54

65
export default function Icon({
76
name,
@@ -25,55 +24,33 @@ export default function Icon({
2524
}
2625
if (name && uri) {
2726
throw new Error(
28-
"Icon component requires either a name or a uri prop, not both.",
27+
"Icon component requires either a name or a uri prop, not both."
2928
);
3029
}
3130

3231
if (name) {
3332
return (
34-
<span
35-
className={
36-
`material-icons${variant ? "-" + variant : ""}` +
37-
(className ? " " + className : "")
38-
}
39-
>
40-
{name}
41-
</span>
33+
<div className="flex justify-center items-center w-full h-full">
34+
<span
35+
className={
36+
`material-icons${variant ? "-" + variant : ""}` +
37+
(className ? " " + className : "")
38+
}
39+
>
40+
{name}
41+
</span>
42+
</div>
4243
);
4344
}
4445

4546
if (!isThemed) {
4647
const iconUri = uri + extension;
47-
return (
48-
<Image
49-
src={iconUri}
50-
alt="icon"
51-
width={24}
52-
height={24}
53-
className={className}
54-
/>
55-
);
48+
return <img src={iconUri} alt="icon" className={"h-6 w-6 " + className} />;
5649
} else if (resolvedTheme === "dark") {
5750
const darkUri = uri + "-dark" + extension;
58-
return (
59-
<Image
60-
src={darkUri}
61-
alt="icon"
62-
width={24}
63-
height={24}
64-
className={className}
65-
/>
66-
);
51+
return <img src={darkUri} alt="icon" className={"h-6 w-6 " + className} />;
6752
}
6853

6954
const lightUri = uri + "-light" + extension;
70-
return (
71-
<Image
72-
src={lightUri}
73-
alt="icon"
74-
width={24}
75-
height={24}
76-
className={className}
77-
/>
78-
);
55+
return <img src={lightUri} alt="icon" className={"h-6 w-6 " + className} />;
7956
}

web/components/modals/extension-modal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ function ExtensionPreview({
365365
</ContextMenu>
366366
</div>
367367
<p className="text-center">{extension.config.id}</p>
368+
<p className="text-center">{extension.config.version}</p>
368369
</div>
369370
);
370371
}

web/components/providers/remote-extension-provider.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { ReactNode } from "react";
66
import ReactDOM from "react-dom";
77
import { EditorContext } from "./editor-context-provider";
88

9-
init({
9+
const host = init({
1010
name: "pulse_editor",
1111
remotes: [],
1212
shared: {
@@ -64,6 +64,7 @@ export default function RemoteExtensionProvider({
6464

6565
// TODO: Use mf-manifest.json to get the css file name
6666
const pattern = /\.css/;
67+
// CSS from Pulse Editor itself
6768
const trustedOrigins = ["http://localhost:3000"];
6869
const observer = new MutationObserver((mutations) => {
6970
mutations.forEach((mutation) => {
File renamed without changes.

web/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,12 @@
3737
"react-dom": "^19.1.0",
3838
"react-hot-toast": "^2.5.2",
3939
"react-responsive": "^10.0.1",
40-
"react-spinners": "^0.16.1",
40+
"react-spinners": "^0.17.0",
4141
"swr": "^2.3.3",
4242
"tesseract.js": "^6.0.1"
4343
},
4444
"devDependencies": {
45-
"@module-federation/runtime": "^0.12.0",
45+
"@module-federation/runtime": "^0.13.0",
4646
"@tailwindcss/postcss": "^4.1.4",
4747
"@types/node": "^22",
4848
"@types/react": "^19",

0 commit comments

Comments
 (0)