Skip to content

Commit a01478d

Browse files
chore: update lazy documentation
1 parent f00bce5 commit a01478d

File tree

4 files changed

+10
-95
lines changed

4 files changed

+10
-95
lines changed

docs/react-integration.asciidoc

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,14 @@ If these parameters are not provided, the defaults documented in <<transaction-a
9999
[float]
100100
===== Instrumenting lazy loaded routes
101101

102-
When the route is rendered lazily with components using `React.lazy` or a similar API, it is currently not possible to
103-
auto instrument the components dependencies via `ApmRoute`. To instrument these lazy rendered routes and capture the spans
104-
associated with the components, you'll need to manually instrument the code with the `withTransaction` API.
102+
When the route is rendered lazily with components using `React.lazy` or a
103+
similar API, it is currently not possible to auto instrument the components
104+
dependencies(JavaScript bundles, API calls, etc) via `ApmRoute` because React
105+
suspends the underlying component until the required dependencies are available
106+
which means our transaction is not started till React starts rendering the
107+
underlying component. To instrument these lazy rendered routes and capture the
108+
spans associated with the components, you'll need to manually instrument the
109+
code with the `withTransaction` API.
105110

106111
[source,js]
107112
----

packages/rum-react/test/e2e/components/lazy-component.js

Lines changed: 0 additions & 50 deletions
This file was deleted.

packages/rum-react/test/e2e/with-router/switch.e2e-spec.js

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const { waitForApmServerCalls } = require('../../../../../dev-utils/webdriver')
2727

2828
describe('Using Switch component of react router', function() {
2929
it('should render the react app on route change', function() {
30-
browser.url('/test/e2e/with-router/switch.html')
30+
beforeAll(() => browser.url('/test/e2e/with-router/switch.html'))
3131
browser.waitUntil(
3232
() => {
3333
/**
@@ -58,36 +58,4 @@ describe('Using Switch component of react router', function() {
5858
expect(routeTransaction.spans.length).toBe(1)
5959
expect(routeTransaction.spans[0].name).toBe('GET /test/e2e/data.json')
6060
})
61-
62-
it('should capture spans inside lazy rendered components', function() {
63-
browser.url('/test/e2e/with-router/switch.html')
64-
browser.waitUntil(
65-
() => {
66-
$('#lazy-func').click()
67-
const componentContainer = $('#lazy-container')
68-
return componentContainer.getText().indexOf('/lazy') !== -1
69-
},
70-
5000,
71-
'expected functional component to be rendered'
72-
)
73-
74-
const { sendEvents } = waitForApmServerCalls(0, 2)
75-
const { transactions } = sendEvents
76-
expect(transactions.length).toBe(2)
77-
78-
const pageLoadTransaction = transactions[0]
79-
expect(pageLoadTransaction.type).toBe('page-load')
80-
expect(pageLoadTransaction.name).toBe('/notfound')
81-
82-
const routeTransaction = transactions[1]
83-
expect(routeTransaction.name).toBe('/lazy')
84-
expect(routeTransaction.type).toBe('route-change')
85-
86-
/**
87-
* 2 Spans
88-
* 1 lazy loaded component JS with 'resource' type
89-
* 1 Fetch call with 'external' type
90-
*/
91-
expect(routeTransaction.spans.length).toBe(2)
92-
})
9361
})

packages/rum-react/test/e2e/with-router/switch.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,13 @@
2525

2626
import '@babel/polyfill'
2727
import 'whatwg-fetch'
28-
import React, { Suspense, lazy } from 'react'
28+
import React, { Suspense } from 'react'
2929
import { render } from 'react-dom'
3030
import { BrowserRouter, Link, Switch } from 'react-router-dom'
3131
import FunctionalComponent from '../components/func-component'
3232
import { ApmRoute } from '../../../src'
3333
import createApmBase from '..'
3434

35-
const LazyFuncComponent = lazy(() => import('../components/lazy-component'))
36-
3735
const apm = createApmBase({
3836
logLevel: 'debug',
3937
serviceName: 'apm-agent-rum-switch-e2e-react',
@@ -51,15 +49,9 @@ function App() {
5149
Functional
5250
</Link>
5351
</li>
54-
<li>
55-
<Link id="lazy-func" to="/lazy">
56-
Lazy
57-
</Link>
58-
</li>
5952
</ul>
6053
<Suspense fallback={<div>Loading...</div>}>
6154
<Switch>
62-
<ApmRoute path="/lazy" component={LazyFuncComponent} />
6355
<ApmRoute path="/func" component={FunctionalComponent} />
6456
<ApmRoute component={NotFound} />
6557
</Switch>

0 commit comments

Comments
 (0)