Replies: 4 comments 2 replies
-
Interesting. Option 3 sounds like an interesting one to explore a little further to me. Moving towards instead of away from the standard (i.e. react-scripts) always seems like the more appealing option to me in general. |
Beta Was this translation helpful? Give feedback.
-
Thanks @Mohammer5 ! I don't think we can consider option 3 as described, since it breaks the whole purpose of app platform abstraction, would require all current platform apps to revert to CRA apps, and would block us from implementing some critical roadmap features like (1) global shell, (2) dynamic modules, (3) standardized routing, (4) granular per-app permissions, and (5) out-of-the-box SSR and SSG. Similarly, we should avoid I think there is probably a variant on 2 which would be ideal here - the shell should be either a thin bootstrap script and HTML (a la single-spa's root config) with a React micro-frontend each for app and for headerbar/login modal/etc or (probably easier initially without dynamic modules) the shell should initialize a modern React 17+ root and provide that to the app. The app could optionally create sub-roots (using single-spa Parcel-like render delegation) which make use of different React versions. For example:
The shell could be exactly as it is now but with
Within the LegacyApp, which has a React 15 dependency and its own node_modules, the entrypoint could expose an API similar to single-spa parcels with |
Beta Was this translation helpful? Give feedback.
-
@Mohammer5 I made a quick example of the multi-react workspace / multiple package approach here - multi-react-app, legacy-react-lib Not tested (ran into an unrelated yarn issue and didn't have a chance to debug) but that's the general idea. There are certainly drawbacks to building a lib rather than an app (i.e. In the glorious future apps (and components) should be self-contained with the ability to share compatible-version dependencies (this is the dynamic modules approach, see dhis2/app-platform#529) so that apps or parts of apps could even use |
Beta Was this translation helpful? Give feedback.
-
Meeting notes, 2021-09-21
Follow-ups
|
Beta Was this translation helpful? Give feedback.
-
This is still a draft! I want to write down what I have in my head before discussing this on Tuesday with @varl and @amcgee
Terminology:
src
directory,with an entry point, specified in the
d2.config.js
src
that hasits own
package.json
.d2/shell
; Has adependecy to
react
&react-dom
app-shell; Must not have
react
/react-dom
dependenciesversion (the one that calls
reactDOM.render(..)
)How does the multi-version approach work in general
<root>/package.json
does not have any react/react-dom dependencies(version would be ambiguous)
<root>/src/*/package.json
(or deeper, but I assume that we should considerthat bad practice)
<root>/src/index.js
imports theindex.js
of the latest react version,e. g.
import './modern/index.js'
. It doesn't have to do anything elseindex.js
of the latest react version callsreactDOM.render(...)
the component and bridge contexts
loading helper that provides the context values to the functions provided by
the legacy apps
Current issues with our setup
package.json
s in thesrc
folderPossibilities I've discovered so far
What needs to be figured out:
bad practice and allowing it might result in projects more
complicated/complex than we want to
section by section
legacy apps; React recommends to try to narrow down the required code for
older react-versions as it's generally discourages to have multiple
versions
the react version would be ambiguous)
lazyLegacyRoot
&createLegacyApp
helpersadditional, custom contexts, these must be forwarded as well, so this
can't be generic
reactDOM.render
as that needs to be done in the app with thelatest react version
Possiblility 1 - The app-platform can differentiate between single- and multi-version projects
For multi-version, the app-platform must:
cd
into the app directories and runyarn install
src/shared
into the individual app directoriessrc/shared
directory to replace previous copies on changeHow to detect single/multi version project:
src/*/package.json
Possibility 2 - The app-shell already has the setup for multiple versions and has the app with react@17
src/*/package.json
, then the src folder can becopied into the app-shell
The package.json will be merged into the default package.json of the
app-shell
Possibility 3 - We turn app-shell into a library with a single component and clone
create-react-app
EDIT:
We turn app-shell into a library
- This is already done by the app-adapter, there's not much we have to change thereIn this approach, instead of having our own app-platform, we reduce the
complexity of the app-platform by getting rid of it, the build steps, etc.
Instead of using a
d2.config.js
, we used2.config.json
. CRA supportsimporting
.json
files, no need to alter the webpack/build configuration.d2 app scripts init
becomes an alias forcreate-react-app [...args] --scripts-version @dhis2/create-react-app
The env vars set in the build script could be moved to
.env.production
,.env.development
and could be overwritten with.env.production.local
or.env.development.local
(which should be git-ignored). Others could be movedto the
@dhis2/app-shell
component, i. e. the component could read thestandalone
config from the env vars, which would allow us to movesetAppParameters to the app-shell component.
Why consider this approach?
work. Right now I can't tell what would be more work: Extending our setup in
a way that deviates from CRA, possibly causing us to deviate more and more
from CRA over time, which might bite us in the future. There's a possibility
that cloning CRA requires less work, reduces complexity and could allow us to
delete code that we wouldn't have to support anymore. IMO at least worth
investigating this option.
@dhis2/cli-app-scripts
test
script that has some discrepencies with CRA'stest
scriptbuild
andstart
(leaving us with a command for generating i18n files)
react-scripts
standard behavior.conflicts
or will be implemented in the future (e. g. multiple react versions)
@dhis2/app-shell
could be used in thesrc/App.js
orsrc/modern/App.js
individual legacy components)
Beta Was this translation helpful? Give feedback.
All reactions