Skip to content
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

ModernJS async boundary #3279

Draft
wants to merge 57 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
9df3cf5
use lerna 6 and uninstall any newer
ScriptedAlchemy Oct 26, 2023
33e7ec5
Merge branch 'master' into lerna-v6
ScriptedAlchemy Oct 26, 2023
6b30bf9
lerna 7 repair attempt
ScriptedAlchemy Oct 26, 2023
2e01049
lerna 7 repair attempt
ScriptedAlchemy Oct 26, 2023
8ceaca8
lerna 7 repair attempt
ScriptedAlchemy Oct 26, 2023
2fa8001
vmok async startup
ScriptedAlchemy Oct 26, 2023
d7f30c1
vmok async startup
ScriptedAlchemy Oct 27, 2023
acc7833
improve await boundary
ScriptedAlchemy Oct 27, 2023
8a1dd2f
improve await boundary
ScriptedAlchemy Oct 27, 2023
bf350aa
use lerna cmds
ScriptedAlchemy Oct 29, 2023
73b82ab
Merge branch 'master' into nested-workspace
ScriptedAlchemy Oct 29, 2023
3cef347
Merge branch 'master' into nested-workspace
ScriptedAlchemy Oct 29, 2023
54df9e8
Merge branch 'master' into nested-workspace
ScriptedAlchemy Oct 29, 2023
346c13d
private workspaces
ScriptedAlchemy Oct 29, 2023
d9699c3
Merge remote-tracking branch 'origin/nested-workspace' into nested-wo…
ScriptedAlchemy Oct 29, 2023
eeb0c86
private workspaces
ScriptedAlchemy Oct 29, 2023
d736cf2
private workspaces
ScriptedAlchemy Oct 29, 2023
1e8def2
private workspaces
ScriptedAlchemy Oct 29, 2023
54285f1
private workspaces
ScriptedAlchemy Oct 30, 2023
1a37363
private workspaces
ScriptedAlchemy Oct 30, 2023
1ef4a8c
cache yarn global cache always
ScriptedAlchemy Oct 30, 2023
08fc9b7
cache yarn global cache always
ScriptedAlchemy Oct 30, 2023
6dd8f88
cache yarn global cache always
ScriptedAlchemy Oct 30, 2023
61bbe17
cache yarn global cache always
ScriptedAlchemy Oct 30, 2023
e4c237c
cache yarn global cache always
ScriptedAlchemy Oct 30, 2023
cb15351
parallel cache ci
ScriptedAlchemy Oct 30, 2023
0c3c9f6
parallel cache ci
ScriptedAlchemy Oct 30, 2023
4c94bc2
parallel cache ci
ScriptedAlchemy Oct 30, 2023
8c25cc7
parallel cache ci
ScriptedAlchemy Oct 30, 2023
e1d7613
parallel cache ci
ScriptedAlchemy Oct 30, 2023
250f39c
install cache restore global
ScriptedAlchemy Oct 30, 2023
a9df88f
install cache restore global
ScriptedAlchemy Oct 30, 2023
a6c885a
install cache restore global
ScriptedAlchemy Oct 30, 2023
2e6b943
install cache restore global
ScriptedAlchemy Oct 30, 2023
d3bcdf0
install cache restore global
ScriptedAlchemy Oct 30, 2023
8dc1b84
install cache restore global
ScriptedAlchemy Oct 30, 2023
a420f80
Merge branch 'master' into nested-workspace
ScriptedAlchemy Oct 30, 2023
a8b2fcf
install cache restore global
ScriptedAlchemy Oct 30, 2023
9e5c70a
improve await boundary
ScriptedAlchemy Oct 30, 2023
dd97d66
improve await boundary
ScriptedAlchemy Oct 30, 2023
cfa2c2c
fix e2e in CI
ScriptedAlchemy Oct 30, 2023
e587b7b
fix e2e in CI
ScriptedAlchemy Oct 30, 2023
9cf819e
cache node module on yarn hash
ScriptedAlchemy Oct 30, 2023
6805da4
Merge branch 'master' into vmok-async-boundary
ScriptedAlchemy Oct 30, 2023
5926135
cache node module on yarn hash
ScriptedAlchemy Oct 30, 2023
cc17c3b
cache node module on yarn hash
ScriptedAlchemy Oct 30, 2023
c110c49
cache node module on yarn hash
ScriptedAlchemy Oct 30, 2023
7a10003
cache node module on yarn hash
ScriptedAlchemy Oct 30, 2023
c6d6497
feat: ModernJS implement async boundary.
ScriptedAlchemy Oct 31, 2023
391df91
Merge branch 'modernjs-async-boundary' into vmok-async-boundary
ScriptedAlchemy Oct 31, 2023
db8ed3d
Merge branch 'master' into vmok-async-boundary
ScriptedAlchemy Oct 31, 2023
279d86c
feat: ModernJS implement async boundary.
ScriptedAlchemy Oct 31, 2023
4411093
improve await boundary
ScriptedAlchemy Oct 31, 2023
5f3cb5c
Merge remote-tracking branch 'origin/vmok-async-boundary' into vmok-a…
ScriptedAlchemy Oct 31, 2023
5b0028d
fix next quirks
ScriptedAlchemy Oct 31, 2023
5f308e4
fix next issues
ScriptedAlchemy Oct 31, 2023
6ac1e2f
Merge remote-tracking branch 'origin/vmok-async-boundary' into vmok-a…
ScriptedAlchemy Oct 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ jobs:
- name: Create matrix
id: set-matrix
run: |
npm install lerna@6 -g
matrix="$(node checkChangedWorkspaces.js)"
echo "matrix=$matrix" >> $GITHUB_OUTPUT

Expand Down Expand Up @@ -208,7 +207,7 @@ jobs:
# TODO Uncomment when yarn will work properly from the root and install all nessessary deps. Also please, add yarn install to the run section below instead of npx lerna exec
# if: steps.yarn-cache.outputs.cache-hit != 'true'
run: |
lerna exec --stream --scope="${{ matrix.container }}*" --concurrency=1 "yarn install"
npx lerna exec --stream --scope="${{ matrix.container }}*" --concurrency=1 "yarn install"

- name: Check disk space after install
run: |
Expand All @@ -222,9 +221,7 @@ jobs:
- name: Run sample e2e tests
run: |
node -v
yarn add lerna@6 -W
yarn add lerna@6 -g
lerna run --scope=${{ matrix.container }} e2e:ci
npx lerna run --scope=${{ matrix.container }} e2e:ci

- name: Create artifacts for Allure report
uses: actions/upload-artifact@v3
Expand Down
13 changes: 12 additions & 1 deletion complete-react-case/main-app/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
import('./bootstrap.js');
const promises = []
__webpack_require__.f.remotes('main',promises);
await Promise.all(promises);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hardcoded to main as proof of concept, in reality this would be part of codegen, injected into all entrypoint modules, each passing their own chunkID to the handlers.
effectively making startup asynchronous.

You can also export require(bootstrap) back out, however - the entrypoint will always export a promise. If webpack is handling this entrpoint loading, then async modules will resolve their inner promises. If not, your entrypoint will always export Promise.resolve(module.exports).

In most cases this should not be a problem, as the act of loading an entrypoint is async in ietslf so much should not experience an issue.

The other option involves replacing entrypoint startup code with a promise based export

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not required if we use the AsyncBoundaryPlugin from modernjs example

console.log(promises)
const thing = await new Promise((r)=>r('test'))
console.log(thing);
require('./bootstrap');
if(globalThis.neverTrue) {
// dynamic import data uri
import('data:text/javascript,export default 42');
}
export default {}
1 change: 0 additions & 1 deletion complete-react-case/main-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"private": true,
"version": "1.0.0",
"description": "",
"main": "webpack.config.js",
"scripts": {
"webpack": "webpack --watch",
"serve": "serve dist -p 3002",
Expand Down
4 changes: 4 additions & 0 deletions complete-react-case/main-app/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ module.exports = {
entry: './index.js',
mode: 'development',
devtool: 'hidden-source-map',
cache:false,
// experiments: {
// topLevelAwait: true
// },
output: {
publicPath: 'http://localhost:3002/',
clean: true,
Expand Down
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.0.0",
"npmClient": "yarn",
"useWorkspaces": true
"$schema": "node_modules/lerna/schemas/lerna-schema.json"
}
6 changes: 2 additions & 4 deletions medusa-nx-native-federation-example/packages/dsl/project.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "dsl",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/dsl/src",
"projectType": "application",
Expand All @@ -9,10 +10,7 @@
"outputPath": "dist/dsl",
"index": "packages/dsl/src/index.html",
"main": "packages/dsl/src/app/index.ts",
"assets": [
"packages/dsl/src/assets",
"packages/dsl/src/favicon.ico"
]
"assets": ["packages/dsl/src/assets", "packages/dsl/src/favicon.ico"]
},
"configurations": {
"production": {
Expand Down
12 changes: 2 additions & 10 deletions medusa-nx-native-federation-example/packages/home/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,8 @@
"outputPath": "dist/home",
"index": "packages/home/src/index.html",
"main": "packages/home/src/app/index.ts",
"assets": [
"packages/home/src/assets",
"packages/home/src/favicon.ico"
],
"remotes": [
"nav",
"dsl",
"search",
"utils"
]
"assets": ["packages/home/src/assets", "packages/home/src/favicon.ico"],
"remotes": ["nav", "dsl", "search", "utils"]
},
"configurations": {
"production": {
Expand Down
12 changes: 3 additions & 9 deletions medusa-nx-native-federation-example/packages/nav/project.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "nav",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/nav/src",
"projectType": "application",
Expand All @@ -9,15 +10,8 @@
"outputPath": "dist/nav",
"index": "packages/nav/src/index.html",
"main": "packages/nav/src/app/index.ts",
"assets": [
"packages/nav/src/assets",
"packages/nav/src/favicon.ico"
],
"remotes": [
"dsl",
"search",
"utils"
]
"assets": ["packages/nav/src/assets", "packages/nav/src/favicon.ico"],
"remotes": ["dsl", "search", "utils"]
},
"configurations": {
"production": {
Expand Down
13 changes: 3 additions & 10 deletions medusa-nx-native-federation-example/packages/search/project.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "search",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/search/src",
"projectType": "application",
Expand All @@ -9,16 +10,8 @@
"outputPath": "dist/search",
"index": "packages/search/src/index.html",
"main": "packages/search/src/app/index.ts",
"assets": [
"packages/search/src/assets",
"packages/search/src/favicon.ico"
],
"remotes": [
"nav",
"dsl",
"home",
"utils"
]
"assets": ["packages/search/src/assets", "packages/search/src/favicon.ico"],
"remotes": ["nav", "dsl", "home", "utils"]
},
"configurations": {
"production": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"name": "utils",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "packages/utils/src",
"projectType": "application",
Expand All @@ -9,10 +10,7 @@
"outputPath": "dist/utils",
"index": "packages/utils/src/index.html",
"main": "packages/utils/src/app/index.ts",
"assets": [
"packages/utils/src/assets",
"packages/utils/src/favicon.ico"
]
"assets": ["packages/utils/src/assets", "packages/utils/src/favicon.ico"]
},
"configurations": {
"production": {
Expand Down
3 changes: 2 additions & 1 deletion nextjs-ssr-react-query/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ testem.log
Thumbs.db

# Next.js
.next
.next
.nx/cache
2 changes: 2 additions & 0 deletions nextjs-ssr-react-query/.prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

/dist
/coverage

/.nx/cache
4 changes: 2 additions & 2 deletions nextjs-ssr-react-query/apps/button/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ export default {
displayName: 'button',
preset: '../../jest.preset.js',
transform: {
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest',
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nrwl/next/babel'] }],
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/next/babel'] }],
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/apps/button',
Expand Down
6 changes: 3 additions & 3 deletions nextjs-ssr-react-query/apps/button/next.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { withNx } = require('@nrwl/next/plugins/with-nx');
const { withNx } = require('@nx/next/plugins/with-nx');
const { NextFederationPlugin } = require('@module-federation/nextjs-mf');

const { dependencies } = require('../../package.json');

/**
* @type {import('@nrwl/next/plugins/with-nx').WithNxOptions}
* @type {import('@nx/next/plugins/with-nx').WithNxOptions}
**/
const nextConfig = {
nx: {
Expand Down Expand Up @@ -34,7 +34,7 @@ const nextConfig = {
requiredVersion: dependencies['styled-components'],
},
},
})
}),
);

return config;
Expand Down
27 changes: 17 additions & 10 deletions nextjs-ssr-react-query/apps/button/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"projectType": "application",
"targets": {
"build": {
"executor": "@nrwl/next:build",
"outputs": ["{options.outputPath}"],
"executor": "@nx/next:build",
"outputs": [
"{options.outputPath}"
],
"defaultConfiguration": "production",
"options": {
"root": "apps/button",
"outputPath": "dist/apps/button"
},
"configurations": {
Expand All @@ -20,7 +21,7 @@
}
},
"serve": {
"executor": "@nrwl/next:server",
"executor": "@nx/next:server",
"defaultConfiguration": "development",
"options": {
"buildTarget": "button:build",
Expand All @@ -39,14 +40,16 @@
}
},
"export": {
"executor": "@nrwl/next:export",
"executor": "@nx/next:export",
"options": {
"buildTarget": "button:build:production"
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"executor": "@nx/jest:jest",
"outputs": [
"{workspaceRoot}/coverage/{projectRoot}"
],
"options": {
"jestConfig": "apps/button/jest.config.ts",
"passWithNoTests": true
Expand All @@ -59,10 +62,14 @@
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"executor": "@nx/eslint:lint",
"outputs": [
"{options.outputFile}"
],
"options": {
"lintFilePatterns": ["apps/button/**/*.{ts,tsx,js,jsx}"]
"lintFilePatterns": [
"apps/button/**/*.{ts,tsx,js,jsx}"
]
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions nextjs-ssr-react-query/apps/header/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ export default {
displayName: 'header',
preset: '../../jest.preset.js',
transform: {
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest',
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nrwl/next/babel'] }],
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/next/babel'] }],
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/apps/header',
Expand Down
6 changes: 3 additions & 3 deletions nextjs-ssr-react-query/apps/header/next.config.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
const { withNx } = require('@nrwl/next/plugins/with-nx');
const { withNx } = require('@nx/next/plugins/with-nx');
const { NextFederationPlugin } = require('@module-federation/nextjs-mf');

const { dependencies } = require('../../package.json');

/**
* @type {import('@nrwl/next/plugins/with-nx').WithNxOptions}
* @type {import('@nx/next/plugins/with-nx').WithNxOptions}
**/
const nextConfig = {
nx: {
Expand Down Expand Up @@ -34,7 +34,7 @@ const nextConfig = {
requiredVersion: dependencies['styled-components'],
},
},
})
}),
);

return config;
Expand Down
27 changes: 17 additions & 10 deletions nextjs-ssr-react-query/apps/header/project.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
"projectType": "application",
"targets": {
"build": {
"executor": "@nrwl/next:build",
"outputs": ["{options.outputPath}"],
"executor": "@nx/next:build",
"outputs": [
"{options.outputPath}"
],
"defaultConfiguration": "production",
"options": {
"root": "apps/header",
"outputPath": "dist/apps/header"
},
"configurations": {
Expand All @@ -20,7 +21,7 @@
}
},
"serve": {
"executor": "@nrwl/next:server",
"executor": "@nx/next:server",
"defaultConfiguration": "development",
"options": {
"buildTarget": "header:build",
Expand All @@ -39,14 +40,16 @@
}
},
"export": {
"executor": "@nrwl/next:export",
"executor": "@nx/next:export",
"options": {
"buildTarget": "header:build:production"
}
},
"test": {
"executor": "@nrwl/jest:jest",
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
"executor": "@nx/jest:jest",
"outputs": [
"{workspaceRoot}/coverage/{projectRoot}"
],
"options": {
"jestConfig": "apps/header/jest.config.ts",
"passWithNoTests": true
Expand All @@ -59,10 +62,14 @@
}
},
"lint": {
"executor": "@nrwl/linter:eslint",
"outputs": ["{options.outputFile}"],
"executor": "@nx/eslint:lint",
"outputs": [
"{options.outputFile}"
],
"options": {
"lintFilePatterns": ["apps/header/**/*.{ts,tsx,js,jsx}"]
"lintFilePatterns": [
"apps/header/**/*.{ts,tsx,js,jsx}"
]
}
}
},
Expand Down
4 changes: 2 additions & 2 deletions nextjs-ssr-react-query/apps/host/jest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ export default {
displayName: 'host',
preset: '../../jest.preset.js',
transform: {
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nrwl/react/plugins/jest',
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nrwl/next/babel'] }],
'^(?!.*\\.(js|jsx|ts|tsx|css|json)$)': '@nx/react/plugins/jest',
'^.+\\.[tj]sx?$': ['babel-jest', { presets: ['@nx/next/babel'] }],
},
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
coverageDirectory: '../../coverage/apps/host',
Expand Down
Loading
Loading