Question: Why do we see logs in the following format?
CSR fallback: rendering in progress
Every time a new request arrives at the SSR, the renderResponse function in the file spartacus-setup-ssr.js is called.
In it, this.shouldRender is called to evaluate how this request should be handled.
In shouldRender:
step1: Evaluate whether the current concurrent number reaches the upper limit. The evaluation logic is done by comparing the current concurrency value (maintained in this.concurrency) with the options passed by the customer (this.ssrOptions.concurrency ):
Source code:
const concurrencyLimitExceed = ((_a = this.ssrOptions) === null || _a === void 0 ? void 0 : _a.concurrency) ? this.currentConcurrency >= this.ssrOptions.concurrency
: false;
step2: Evaluate whether the same page has already been rendered.
const isRendering = this.renderingCache.isRendering(this.getRenderingKey(request));
How to judge whether two rendering requests represent the same page?
This is done by the function this.getRenderingKey(request) in line 97.
The default differentiation logic is to use the originalUrl field of the request, that is, if the originalUrl of two requests is the same, SSR treats them as the same page.
How to judge whether a given page already has an ongoing rendering process?
In the RenderingCache class of spartacus-setup-ssr.js, we use Map to maintain the rendering process of each page through a key-value structure, see line 9 below.
By default, the key is the originalUrl of the request, and the value is an object containing a Boolean flag: true or false.
If a given value equal to true can be found in the Map of RenderingCache, we think that the given page is being rendered. At the same time, if another request has the same page key (ie the same originalUrl), we will not provide the second request through SSR, but trigger a CSR rollback and print the log on line 99 below.
Note: The logic of using RenderingCache to record whether the page is being rendered is always on, regardless of the value of the option "cache".
More original articles by Jerry, all in: "Wang Zixi":
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。