Created
October 30, 2023 15:15
-
-
Save brunos3d/ec3de5402b506448c50601236e6985da to your computer and use it in GitHub Desktop.
An example of a common issue when using singleton: true for all shared packages
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// remote | |
// uses xlib@10 as a singleton | |
import { generate } from 'xlib'; // hey, I'm a singleton and I will have only one global instance in memory =] | |
// the federated component | |
export default function GenerateSomethingButton() { | |
const content = generate(); | |
return <h1>{content}</h1>; | |
} | |
// The xlib@10 example | |
function generate () { | |
// ... | |
} | |
module.exports = { generate } | |
// The xlib@11 example: the author decides to rename and adds a deprecation warning message | |
function create () { | |
// ... | |
} | |
module.exports = { | |
create, | |
/** | |
* @deprecated: 'generate' is deprecated use 'create' instead | |
*/ | |
generate: create | |
} | |
// The xlib@12 example the generate export has been removed =,) | |
function create () { | |
// ... | |
} | |
module.exports = { create } | |
// host-1 consuming remote@GenerateSomethingButton | |
// doesn't provide a xlib@10 so it will be loaded using the version 10 from the remote | |
import { generate } from 'xlib'; // this is fine =] | |
// host-2 consuming remote@GenerateSomethingButton | |
// uses xlib@10 as a singleton | |
import { generate } from 'xlib'; // this is fine =] | |
// host-3 consuming remote@GenerateSomethingButton | |
// provides and uses xlib@11 as a singleton | |
import { generate } from 'xlib'; // deprecation warning: 'generate' is deprecated use 'create' instead | |
// host-4 consuming remote@GenerateSomethingButton | |
// provides and uses xlib@12 as a singleton | |
import { generate } from 'xlib'; // xD SyntaxError: The requested module 'xlib' does not provide an export named 'generate' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment