Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat:add online solution links for qiankun #2754

Open
wants to merge 7 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
16 changes: 16 additions & 0 deletions .dumi/pages/error/CodeSnippet.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import React from 'react'

export default function CodeSnippet(props) {
const lines = props.children.split('\n')
const firstTextualLine = lines.find(l => l.trim() !== l)
const numLeadingSpaces = firstTextualLine ? /([^\s])/.exec(firstTextualLine).index : 0
const formattedLines = lines.map(line => line.slice(numLeadingSpaces)).filter((line, i) => line.length > 0 || i > 0).join('\n')
return (
<div className="__dumi-default-code-block">
<pre className="prism-code language-tsx">
{formattedLines}
</pre>
</div>

)
}
54 changes: 54 additions & 0 deletions .dumi/pages/error/codes/1.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from 'react'
import CodeSnippet from '../CodeSnippet'

export default function ErrorCode1(props) {
return (
<>
<h1>#1: Application died in status NOT_MOUNTED: Target container with #container not existed after {props.getErrorCodeArg(0)} mounted!</h1>
<p>
This error thrown as the container DOM does not exist after the micro app is loaded. The possible reasons are:
</p>
<h4>
1.The root id of the micro app conflicts with other DOM, and the solution is to modify the search range of the root id.
</h4>
<div>
<h4>vue micro app:</h4>
<CodeSnippet>
{`
function render(props = {}) {
const { container } = props;
instance = new Vue({
router,
store,
render: (h) => h(App),
}).$mount(container ? container.querySelector('#app') : '#app');
}
export async function mount(props) {
render(props);
}
`}
</CodeSnippet>
<h4>react micro app:</h4>
<CodeSnippet>
{ `
function render(props) {
const { container } = props;
ReactDOM.render(<App />, container ? container.querySelector('#root') : document.querySelector('#root'));
}
export async function mount(props) {
render(props);
}
export async function unmount(props) {
const { container } = props;
ReactDOM.unmountComponentAtNode(container ? container.querySelector('#root') : document.querySelector('#root'));
}
`}
</CodeSnippet>
</div>
<h2>Explanation:</h2>
<p>
<a href="/qiankun/faq#application-died-in-status-not_mounted-target-container-with-container-not-existed-after-xxx-mounted">FAQ</a>
</p>
</>
)
}
29 changes: 29 additions & 0 deletions .dumi/pages/error/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* sidebar: false
*/

import React from 'react'
import { useLocation, useParams } from 'react-router-dom';
import Error1 from './codes/1'
import { useSearchParams } from 'dumi';
const r = require.context('./codes/', false, /\.tsx$/);

export default function CodeSnippet() {
let [searchParams, setSearchParams] = useSearchParams();
const code = searchParams.get('code');
const Comp = code && r(`./${code}.tsx`).default;
const errorCodeArgs = searchParams.getAll('arg');

return code ? (
<div>
<Comp errorCodeArgs={errorCodeArgs}
getErrorCodeArg={getErrorCodeArg}
errorCode={code} />
</div>
) : (<div>请输入错误码code</div>)
kuitos marked this conversation as resolved.
Show resolved Hide resolved

function getErrorCodeArg(index, argName) {
const missingArg = argName ? `(${argName})` : `(unknown)`;
return errorCodeArgs.length > index ? errorCodeArgs[index] : missingArg;
}
}
1 change: 1 addition & 0 deletions .dumirc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,5 @@ export default defineConfig({
theme: {
'@c-primary': '#6451AB',
},
styles: [`li a[href="/qiankun/error"],li a[href="/qiankun/error"] ~ * { display: none}]`],
});
7 changes: 7 additions & 0 deletions packages/shared/src/error/QiankunError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,10 @@ export class QiankunError extends Error {
super(`[qiankun]: ${message}`);
}
}

export class QiankunError2 extends Error {
gjmhandsome marked this conversation as resolved.
Show resolved Hide resolved
constructor(code: number, message: string, ...args: string[]) {
super(`[qiankun #${code}]: ${message ? message + " " : ""}See https://qiankun.umijs.org/error/?code=${code}${args.length ? `&arg=${args.join("&arg=")}` : ""
}`);
}
}
Loading