-
Notifications
You must be signed in to change notification settings - Fork 67
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
[Bug]: FetchPlugin
does not support server-side rendering
#415
Comments
Hi Charles, web clients should not be initialized on a server - is there a specific reason why you wish to do so? |
I'm server rendering a React application, so the client side runtime code is also executing on the server. |
Hi, does this issue mean that RUM is not supported when server-side rendering is enabled on frameworks such as NextJS? This should be clearly noted, as NextJS is currently the recommended React framework, and is a blocker to teams using server-side rendering. @CharlesStover , did you find a way around this for your use case? |
You can use You can use I forget which path I ended up going. |
When initialized, the web client (1) performs steps to get credentials, and (2) emits a session start event. I believe both of these events can be deferred. Regarding (2), initialize the web client in the disabled state by setting This setting is currently missing from the docs, which we should fix. The use of this setting is demonstrated in this blog. Regarding (1), omit the We may want to do something so that credentials are not fetched when the web client is disabled, in which case the application need only flip the web client from disabled to enabled when it is ready. |
Please re-open if this doesn't work or if you have thoughts on a better solution. Meanwhile, we'll add these to the backlog. |
I'll give those a try. As a placeholder, I've seen as a common pattern for SSR+CSR packages to use |
So to clarify, when rendering on a server (i.e., no window object), you expect all calls to the web client to be no-ops? |
Yes, server-rendering serves primarily to generate the initial DOM. Once passed to the client, React will "hydrate," re-executing the render to (1) build the virtual DOM into memory [since the actual DOM is already present] and (2) execute any non-DOM side effects. For example, instantiating RUM and monitoring web vitals does not impact the initial DOM or view, so this behavior does not need to occur during the initial server render. There's no value in having a RUM object in server memory, but once the application re-hydrates on the client, RUM can instantiate in memory and perform browser-based actions like fetching and web vitals. For a server-side rendered application, the application code is executed once on the server to build the initial DOM and again on the client to hydrate the application into browser memory. By saying "only perform this actions when the On the server (or any environment where For power user inversion of control, you could perhaps support fetch as a parameter, but I'm really scope-creeping with this.
Again, that's creep-scope, but I think it would help testability. No-op is a great starting point that's compatible with the above stretch goal. Thanks for the attention to the issue. 🙂 |
Agree with @CharlesStover here. Would be great to have a mock/stub implementation of the RUM library. Not only for SSR purposes but also for testability. A great example of this mocking ability is Undici: https://undici.nodejs.org/#/docs/api/MockClient This greatly simplifies testing, and don't need to monkey patch or use |
@moltar If you are using React, my package |
Which web client version did you detect this bug with?
v1.12.0
What environment (build systems, module system, and framework) did you detect this bug with?
Is your web application a single page application (SPA) or multi page application (MPA)?
SPA
Please provide your web client configuration
N/A
Please describe the bug/issue
When instantiating
new AwsRum()
, server-side rendering throws an error:It appears to be trying to call
window.fetch
once instantiated, which of course does not exist.I would like to instantiate
new AwsRum
on the server without it actually connecting to emit any metrics, since there is no user in this context -- there should be nothing to emit, as no events have been triggered.AwsRum
in and of itself should not be connecting to RUM to emit metrics.Please advise. 😊
The text was updated successfully, but these errors were encountered: