-
Notifications
You must be signed in to change notification settings - Fork 110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Local module federation implementation #782
Comments
can you provide a minimal reproduction so we can look into this? thank you |
Hi, @zmzlois, Reference of super app showcase local mfe setup: https://github.com/callstack/super-app-showcase/tree/local-module-federation-poc |
Hi @jbroma / @thymikee / @zmzlois Thanks in advance |
For what its worth, I added my own scrappy script cache by having script load interceptors like following
In your main app have following
import RNFS from 'react-native-fs';
import {Script} from '@callstack/repack/client';
function makeSafeFilename(url: string): string {
// Extract the part of the URL after the domain name (strip the protocol and domain)
const urlPath = url.replace(/^https?:\/\/[^/]+/, '');
// Replace slashes (/) with dashes (-) and append a .js extension
return urlPath.replace(/\//g, '-') + '.js';
}
export const ScriptInterceptor = async function (script: Script, shouldUseCache = true) {
const cacheDir = `${RNFS.DocumentDirectoryPath}/script_cache`;
// Construct the full URL with query parameters
const url = script.locator.query
? `${script.locator.url}?${script.locator.query}`
: script.locator.url;
// Use the full URL as part of the cache key to differentiate scripts with different queries
const cacheKey = script.scriptId;//makeSafeFilename(url);
const cacheFilePath = `${cacheDir}/${cacheKey}.js`;
// Ensure cache directory exists
try {
if (!(await RNFS.exists(cacheDir))) {
await RNFS.mkdir(cacheDir);
}
} catch (dirError: any) {
console.error(`Failed to create cache directory: ${dirError.message}`);
throw dirError;
}
const assignLocatorUrlFromLocalFileSystem = (fileLocation: string, isAbsolutePath = true) => {
// assign script to have absolute path
script.locator.absolute = true;
script.locator.url = fileLocation;
}
// Check if the script is already cached
if (await RNFS.exists(cacheFilePath) && shouldUseCache) {
console.log(`Cache hit for script: ${cacheFilePath}`);
assignLocatorUrlFromLocalFileSystem(`file://${cacheFilePath}`);
console.log('updated path', script.locator.url)
return;
}
console.log(`Downloading script: ${url}`);
try {
const response = await fetch(url, {
method: script.locator.method,
headers: script.locator.headers,
body: script.locator.body,
});
if (!response.ok) {
console.log('error downloading script', response.status, 'for script id:', script.scriptId);
return;
}
const scriptContent = await response.text();
// Cache the script to the filesystem
await RNFS.writeFile(cacheFilePath, scriptContent, 'utf8');
console.log(`Cached script at: ${cacheFilePath}`);
// Update locator to use the file URL
assignLocatorUrlFromLocalFileSystem(`file://${cacheFilePath}`);
} catch (error: any) {
console.error(`Error in interceptor while downloading script: ${error.message}`);
return;
//throw error;
}
}; You do need to patch the ScriptManager.js directly or use patch-package library
|
This issue has been marked as stale because it has been inactive for 30 days. Please update this issue or it will be automatically closed in 14 days. |
Describe the bug
Hi devs,
I was doing a POC on the repack Module Federation implementation with local MFE and could see in the superapp showcase regarding the poc-local-module-federation and could see there are some modifications needed for the mfe to work locally without any server, so i was able to see what changes needs to be done so that it will work on ios, but there were no references on how to implement it android, it would be helpful if anyone can comment on this.
Thank you
System Info
React native 0.74.4
Re.Pack Version
4.4.0
Reproduction
.
Steps to reproduce
.
The text was updated successfully, but these errors were encountered: