我有一个react-redux应用程序在aspnet核心上运行,服务器端渲染使用aspnet预渲染。Aspnet服务器渲染调试
可以说我犯了一个编程错误,在儿童组件中,我尝试访问一个未定义的道具,因为一个愚蠢的错字。
import {Child} from './child'
export class Parent extends React.Component {
render() {
const someProp = {
something: "something"
};
return <Child someProp={someProp} />;
}
}
export class Child extends React.Component {
render() {
return <div>this.props.someprop.something</div>;
//typo: should be someProp instead of someprop
}
没有服务器渲染,我会得到类似这样的错误:在x行不能访问的不确定的东西:YY 但随着serverrendering我得到一个:
An unhandled exception occurred while processing the request.
Exception: Call to Node module failed with error: Prerendering timed out after 30000ms because the boot function in 'ClientApp/src/boot-server' returned a promise that did not resolve or reject. Make sure that your boot function always resolves or rejects its promise. You can change the timeout value using the 'asp-prerender-timeout' tag helper.
这使得调试很难,当你没有得到任何错误的反馈。 任何人知道如何设置一个拒绝,如果失败了?或者甚至有可能调试服务器端呈现的代码?
这里是我的启动服务器文件,告诉我你是否需要更多的文件。
import * as React from 'react';
import { Provider } from 'react-redux';
import { renderToString } from 'react-dom/server';
import configureStore from './store/configureStore';
import {getFormById} from './actions/getFormActions';
import {updateUserLocale} from './actions/userLocaleActions';
import FormResponder from './components/mainComponents/formResponder';
export default function renderApp (params) {
return new Promise((resolve, reject) => {
const store = configureStore();
store.dispatch(getFormById(params.data.id, params.data.config, params.data.authenticationToken));
store.dispatch(updateUserLocale(params.data.userLocale));
const app = (
<Provider store={ store }>
<FormResponder />
</Provider>
);
// Perform an initial render that will cause any async tasks (e.g., data access) to begin
renderToString(app);
// Once the tasks are done, we can perform the final render
// We also send the redux store state, so the client can continue execution where the server left off
params.domainTasks.then(() => {
resolve({
html: renderToString(app),
globals: {
initialReduxState: store.getState(),
authenticationToken: params.data.authenticationToken,
config: params.data.config
}
});
}, reject); // Also propagate any errors back into the host application
});
}
你刚刚救了我疯了! – racamp101