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

fix(ssr): html with single quote parse error #6066

Merged
merged 26 commits into from
Jan 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = {
// disable css files mock for bundler-webpack's css import tests
moduleNameMapper: {},
transformIgnorePatterns: ['/node_modules/'],
transformIgnorePatterns: ['/node_modules/(?!.*@babel)[^/]+?/'],
collectCoverageFrom(memo) {
return memo.concat([
// benchmarks
Expand Down
2 changes: 1 addition & 1 deletion packages/preset-built-in/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"@types/merge-stream": "1.1.2",
"@types/multer": "1.4.3",
"@types/react-router-config": "5.0.1",
"@types/serialize-javascript": "4.0.0",
"@types/serialize-javascript": "5.0.0",
"@umijs/babel-preset-umi": "3.3.7",
"@umijs/bundler-webpack": "3.3.7",
"@umijs/renderer-mpa": "3.3.7",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Bar = props => {
);
};

Bar.getInitialProps = async () => {
Bar.getInitialProps = () => {
return {
title: 'Bar',
};
Expand Down
5 changes: 2 additions & 3 deletions packages/preset-built-in/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ beforeEach(() => {
}
});

afterEach(() => {
cleanup();
});
afterEach(cleanup);

test('api.writeTmpFile error in register stage', async () => {
const cwd = join(fixtures, 'api-writeTmpFile');
Expand Down Expand Up @@ -394,6 +392,7 @@ xtest('ssr dynamicImport', async () => {
'p__Bar.css': '/p__Bar.chunk.css',
};

// without webpack, so export default
const render = require(tmpServerFile).default;
// render /
const homeResult = await render({
Expand Down
3 changes: 2 additions & 1 deletion packages/preset-built-in/src/plugins/features/ssr/ssr.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from 'fs';
import assert from 'assert';
import * as path from 'path';
import serialize from 'serialize-javascript';
import { performance } from 'perf_hooks';
import { Route } from '@umijs/core';
import { IApi, BundlerConfigType } from '@umijs/types';
Expand Down Expand Up @@ -157,7 +158,7 @@ export default (api: IApi) => {
ManifestFileName: api.config.manifest
? api.config.manifest.fileName || 'asset-manifest.json'
: '',
DEFAULT_HTML_PLACEHOLDER: JSON.stringify(defaultHTML),
DEFAULT_HTML_PLACEHOLDER: serialize(defaultHTML),
}),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export const loadPageGetInitialProps = async ({ ctx,
// preload for dynamicImport
if (Component?.preload) {
const preloadComponent = await Component.preload();
Component = preloadComponent.default || preloadComponent;
Component = preloadComponent?.default || preloadComponent;
}

if (Component && (Component as any)?.getInitialProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const render: IServerRender = async (params) => {
const history = createMemoryHistory({
initialEntries: [format(location)],
});

/**
* beforeRenderServer hook, for polyfill global.*
*/
Expand Down Expand Up @@ -104,7 +103,6 @@ const render: IServerRender = async (params) => {
manifest = requireFunc(`./{{{ ManifestFileName }}}`);
} catch (_) {}
}

// renderServer get rootContainer
const { pageHTML, pageInitialProps, routesMatched } = await renderServer(opts);
rootContainer = pageHTML;
Expand Down
4 changes: 2 additions & 2 deletions packages/renderer-mpa/src/renderClient/renderClient.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ beforeEach(() => {
document.body.appendChild(container);
});

afterEach(() => {
afterEach(async () => {
document.body.removeChild(container);
// @ts-ignore
container = null;
cleanup();
await cleanup();
});

test('normal', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ beforeEach(() => {
window.g_initialProps = null;
});

afterEach(() => {
afterEach(async () => {
document.body.removeChild(container);
container = null;
delete window.g_useSSR;
delete window.g_initialProps;
cleanup();
await cleanup();
});

test('normal', async () => {
Expand Down
39 changes: 4 additions & 35 deletions packages/renderer-react/src/renderRoutes/renderRoutes.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import { MemoryRouter, Plugin, Link } from '@umijs/runtime';
import { getByText, render, screen, waitFor } from '@testing-library/react';
import { getByText, render, screen, waitFor, cleanup } from '@testing-library/react';
import renderRoutes from './renderRoutes';
import { IRoute } from '..';

Expand Down Expand Up @@ -206,9 +206,10 @@ beforeEach(() => {
renderCount = 0;
});

afterEach(() => {
afterEach(async () => {
delete window.g_useSSR;
delete window.g_initialProps;
await cleanup();
});

test('/layout', async () => {
Expand Down Expand Up @@ -290,38 +291,6 @@ test('/pass-props', async () => {
expect((await screen.findByTestId('test')).innerHTML).toEqual('bar');
});

test('/get-initial-props', async () => {
const newRoutes = renderRoutes(routerConfig);
const { container } = render(
<MemoryRouter initialEntries={['/get-initial-props']}>
{newRoutes}
</MemoryRouter>,
);
await waitFor(() => getByText(container, 'bar'));
expect((await screen.findByTestId('test')).innerHTML).toEqual('bar');
});

test('/get-initial-props-without-unmount', async () => {
const newRoutes = renderRoutes(routerConfig);
const { container } = render(
<MemoryRouter initialEntries={['/get-initial-props-without-unmount']}>
{newRoutes}
</MemoryRouter>,
);
await waitFor(() => getByText(container, 'bar'));
expect((await screen.findByTestId('test2')).innerHTML).toEqual('bar');
expect(mountCount).toEqual(0);
// hash change
getByText(container, 'link-bar').click();
expect(mountCount).toEqual(0);

// change route
getByText(container, 'change-route').click();
expect(mountCount).toEqual(1);
await waitFor(() => getByText(container, 'bar'));
expect((await screen.findByTestId('test')).innerHTML).toEqual('bar');
});

test('/get-initial-props-with-mount', async () => {
const newRoutes = renderRoutes(routerConfig);

Expand Down Expand Up @@ -355,7 +324,7 @@ test('/get-initial-props-embed', async () => {
);
});

test('/wrappers', async () => {
test('/wrappers', () => {
const { container } = render(
<MemoryRouter initialEntries={['/wrappers']}>{routes}</MemoryRouter>,
);
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3279,10 +3279,10 @@
resolved "https://registry.yarnpkg.com/@types/semver/-/semver-7.3.4.tgz#43d7168fec6fa0988bb1a513a697b29296721afb"
integrity sha512-+nVsLKlcUCeMzD2ufHEYuJ9a2ovstb6Dp52A5VsoKxDXgvE051XgHI/33I1EymwkRGQkwnA0LkhnUzituGs4EQ==

"@types/serialize-javascript@4.0.0":
version "4.0.0"
resolved "https://registry.yarnpkg.com/@types/serialize-javascript/-/serialize-javascript-4.0.0.tgz#ab9c47edf71f6a4590221118d1dffc37b50d71a2"
integrity sha512-y9UO8ozDGF30EVRizmsXuCdZzAxHmYpEEiL+/SQjX+7bnxslkvZQU8rLydixJv7yVae6bWyrNDFHsh6fYHkFMA==
"@types/serialize-javascript@5.0.0":
version "5.0.0"
resolved "https://registry.yarnpkg.com/@types/serialize-javascript/-/serialize-javascript-5.0.0.tgz#127638567bd9f11251ad0ca2d9d9ea9ce5ca4b93"
integrity sha512-2+ai0/OTduvDzJHRAcqDwgNwshL1TN+iAfjzJJogXPSSjTBuqPl7MI0xGqCcPx+PDFbvmziiK1H6bjDb4DcoSA==

"@types/serve-static@*":
version "1.13.8"
Expand Down