Coder Social home page Coder Social logo

single-spa / single-spa Goto Github PK

View Code? Open in Web Editor NEW
13.0K 162.0 910.0 7.32 MB

The router for easy microfrontends

Home Page: https://single-spa.js.org/

License: Other

JavaScript 99.01% TypeScript 0.94% Shell 0.04%
front-end javascript microservices single-spa single-page-applications microfrontends router

single-spa's Introduction

npm version NPM Downloads

single-spa

Join the chat on Slack

Donate to this project

Official single-spa hosting

baseplate-logo-standard

A javascript framework for front-end microservices

Build micro frontends that coexist and can (but don't need to) be written with their own framework. This allows you to:

Sponsors

DataCamp-Logo Toast-Logo asurion-logo

To add your company's logo to this section:

Documentation

You can find the single-spa documentation on the website.

Check out the Getting Started page for a quick overview.

Demo and examples

Please see the examples page on the website.

Want to help?

Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on our guidelines for contributing on the single-spa website.

Contributing

The main purpose of this repository is to continue to evolve single-spa, making it better and easier to use. Development of single-spa, and the single-spa ecosystem happens in the open on GitHub, and we are grateful to the community for contributing bugfixes and improvements. Read below to learn how you can take part in improving single-spa.

Single-spa has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.

Read our contributing guide to learn about our development process, how to propose bugfixes and improvements, and how to build and test your changes to single-spa.

single-spa's People

Contributors

alocke12992 avatar blittle avatar bloody-ux avatar codelittleprince avatar deblasis avatar dependabot[bot] avatar filoxo avatar frehner avatar gitter-badger avatar godky avatar gongshun avatar greenkeeperio-bot avatar joeldenning avatar jrose-carecloud avatar kentmclean avatar krzyswiatkowski avatar kuitos avatar me-12 avatar milankovacic avatar mmemory avatar nhumrich avatar nicholas-johnson avatar petermikitsh avatar pkhodaveissi avatar richtmat avatar sauloxd avatar tannerlyons avatar themcmurder avatar tiagostutz avatar yangdan8 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

single-spa's Issues

The eventArguments given to enqueued calls to reroute are not ever given to the captured event listeners.

When we call callCapturedEventListeners, it only calls the captured event listeners with the current eventArguments, but not any previously queued eventArguments. See https://github.com/CanopyTax/single-spa/blob/e365390ff4fd0ac879edc9b6fc0ae2665b7cc7fa/src/navigation/reroute.js#L99. This matters because the first eventArguments sometimes is a PopStateEvent, and subsequently queued calls have a HashChangeEvent eventArguments. Because there are different event listeners for popstate and hashchange, this is a problem because the hashchange listeners will never be called.

Add a `single-spa:first-mount` event

I could see this being useful for a variety of reasons, but here are a couple I can think of right now:

  • Show a visual loading bar before single-spa apps are mounted, but then get rid of the loader once the first app is mounted. Although this could maybe better be served with a bootstrap hook in the apps, or maybe a single-spa:before-first-mount event so that the loading bar doesn't show up temporarily while apps are mounting.
  • Perform initialization logic that, for performance reasons, you want to defer until after the single-spa apps are up and running.
  • Time how long it takes to initialize the first app in your application.

From an implementation standpoint, I think this could be as simple as dispatching a CustomEvent inside of the mount lifecycle, and just keep track of if it has ever been fired before or not.

Create `unload` lifecycle and `unloadChildApplication` API

This is something the Dealer Socket guys have implemented and found useful for their iframe loading solution. It should work something like this:

// We've decided that this should be unloaded
import {unloadChildApplication} from 'single-spa';
unloadChildApplication('app-name', {waitForUnmount: true});
// Inside of the 'app-name' app
export async function unload() {
  // Do something special here, on a per-app basis
  SystemJS.delete('app-name');
}

This lifecycle would be the first optional lifecycle. What the unloadChildApplication API will do is set the app.status to NOT_LOADED, after calling the unload lifecyle.

An open question is what the default behavior for waitForUnmount should be, and whether this is something that should be configurable or not.

New API. CheckActivityFunction

To enable Server rendering we're going to at least need an API that allows the parent Application to ask Single-spa which children should be active given an arbitrary URL

Add `getAppNames` api

Similar to getMountedApps, except it gives you all of the apps that have ever been declared.

Does single-spa support retrieving apps from a different domain?

I have multiple react applications served on different servers (domains). Can I use single-spa to create a root application that includes these apps as child apps?

Something like this:
singleSpa.declareChildApplication('app1', () => import('http://localhost/MyReactApp/src/child-app.js'), hashPrefix('/app1'));

app2 not deactivated

Hi,
first of all great work!
I'm trying to use your example to see if this tool fit with my requirement and in the angular2 application I tried to add a simple router example. the angular 2 works great but when I try to switch to react (after angular2 has been loaded) it fail because angular2 is not unmounted and it try to find the path app1.

this is the repository that I created: https://github.com/daniele-zurico/microservice-test

RFC: Server Rendering

Some single-spa applications may want to server render some or all of the child applications that are active for a url. How to pull that off is not decided, but here's what I'm thinking for it so far:

const location = {href: '/url#/hash', hash: '#/hash'};
// New API for single-spa returns an array of string names.
const activeAppNames = singleSpa.findActiveApplications(location);

// The serverRender API will load the app but will probably not bootstrap it and will definitely not mount it. Instead it will check
// for a new lifecycle method (serverRender?) on the application. If the lifecycleMethod exists, it calls it. If not, it returns an empty string
Promise
  .all(activeAppNames.map(singleSpa.serverRender))
  .then(serverRenderedHtmls => {
    const finalHtml = serverRenderedHtmls.join("");
    res.write(finalHtml);
  })

Advantages of doing it that way:

  • The user of single-spa can control which applications to server render
  • findActiveApplications might have other use cases besides server rendering

Disadvantages:

  • You have to load the child application before you even know whether it supports server rendering or not. I'm not sure how this would be solved in any other way, though, besides perhaps including some configuration during declareChildApplication.

Reduce bundle size

Right now single-spa is an embarrassing 55kb with minification and mangling (webpack -p). But a lot of that is because single-spa uses async/await, which requires the babel regenerator runtime which is pretty large. So to fix this, we could remove all the async/await code in single-spa itself.

Transitions/animations between apps

My ideas about this are vague and we've had a couple of small discussions about it, but I think that single-spa support might be needed for animations/transitions between apps because it is really the only thing that knows when apps are mounting and unmounting.

Not sure about implementation options or details, but would love to discuss it if anyone has ideas.

Better error messaging if an app fails to load

Currently the error messaging for a systemjs app that fails to load correctly is something like this:

Uncaught Error: "does not export an unmount function or array of functions". It should say something like this: App 'my-app' could not be loaded - could not resolve dependency "lodash"

Combining multiple version of the same framework

I was wondering if single-spa allows combining multiple child applications using different versions of the same framework. Say i have two team that want to combine an angular2 and angular4 child app into the same page. Can the framework handle this? I would think not since this would trigger conflicts in the browser.

Question regarding multiple child apps

Hi,

We are in the process of figuring out how to extend our angular 1.5 app with 2.0 child apps. single-spa seems like a great candidate. I was curious to know if there is any documentation regarding having child apps use their own package.json file instead of there being a globally defined package.json file for all child apps. Is this presently possible with single-spa?

single-spa post install requires JSPM

You cannot run an npm install single-spa --save on a system that doesn't have JSPM installed.

Reproduction steps

  1. Ensure that you have a version of node/npm that doesn't have JSPM (I just used nvm to switch to a new version)
  2. Create a new directory then run npm init in the new directory
  3. run npm install single-spa --save

Replace SystemJS with Webpack?

Hi, I was wondering what the feeling is about replacing SystemJS with Webpack? SystemJS is fine, but Webpack is the standard. Use of SystemJS will likely hurt adoption.

Sharing data and state between micro-apps via Redux?

Hi there @joeldenning,

I came across this project and think it's pretty awesome. It seems to function very closely to how we want to do things at my company. My UI team has been talking more about how we can create a system that can work very much like how this does.

We would, however, require the ability to share data between the loaded micro apps somehow, and would also like to be able to manage the state as well. I may have missed it in the docs, but is this something that is possible currently, or do you know if there is anyone doing anything similar?

We want to be able to develop the different parts of our currently very monolithic application as smaller independent apps that can co-exist and communicate together through some kind of state management (redux) or other kind of interface.

Would love to hear your thoughts on this.

Thanks!
Jared

Coding splitting child apps

Hi there, great framework. Thanks for sharing!

Do child apps need to be a single bundle or can they be code splitted?

As an exercise I converted https://github.com/AngularClass/angular-starter into a single-spa child and it successfully mounted onto my root single-spa app. However, it fails on certain routes within the child app, as it tries loading its chunk from the root app

GET http://127.0.0.1:8080/1.chunk.js

rather than the location of the child app on the filesystem.

What's the best strategy to enable on-demand loading of chunks for child apps? Or do I import every chunk in declareChildApplication?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.