我有一個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