Skip to content

Commit

Permalink
feat(rum-react)!: support react-router 6 (#1410)
Browse files Browse the repository at this point in the history
  • Loading branch information
devcorpio authored Aug 8, 2023
1 parent aeb75dd commit 401c9dd
Show file tree
Hide file tree
Showing 21 changed files with 597 additions and 442 deletions.
6 changes: 6 additions & 0 deletions dev-utils/test-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ function getBrowserList(pkg = 'default') {
let browsers = []
if (pkg === 'default') {
browsers = getDefaultBrowsers()
} else if (pkg === 'react') {
// react router 6 doesn't support IE 11, we get rid of it
// https://github.com/remix-run/react-router/issues/8220#issuecomment-961326123
return getDefaultBrowsers().filter(
browser => browser.browserName != 'internet explorer'
)
} else if (pkg === 'vue') {
// Vue 3 dropped support for IE 11 and older browsers,
// so we use modern browsers ro run the tests
Expand Down
112 changes: 15 additions & 97 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@
"puppeteer": "^13.0.0",
"react": "^17.0.2",
"react-dom": "^17.0.2",
"react-router": "^5.2.0",
"react-router-dom": "^5.2.0",
"react-router": "^6.14.2",
"react-router-dom": "^6.14.2",
"regenerator-runtime": "^0.13.3",
"rimraf": "^3.0.0",
"rxjs": "^6.6.6",
Expand Down
7 changes: 6 additions & 1 deletion packages/rum-react/karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/

const { baseConfig, prepareConfig } = require('../../dev-utils/karma.js')
const { getBrowserList } = require('../../dev-utils/test-config')
const {
getWebpackConfig,
PACKAGE_TYPES,
Expand All @@ -33,7 +34,11 @@ const {
module.exports = function (config) {
config.set(baseConfig)
config.set({
webpack: getWebpackConfig(BUNDLE_TYPES.BROWSER_DEV, PACKAGE_TYPES.REACT)
webpack: getWebpackConfig(BUNDLE_TYPES.BROWSER_DEV, PACKAGE_TYPES.REACT),
customLaunchers: getBrowserList('react').map(launcher => ({
...launcher,
base: 'SauceLabs'
}))
})
const preparedConfig = prepareConfig(config, 'rum-react')
config.set(preparedConfig)
Expand Down
2 changes: 1 addition & 1 deletion packages/rum-react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
},
"peerDependencies": {
"react": ">16.0.0",
"react-router-dom": ">4.0.0"
"react-router-dom": ">=6.0.0"
},
"browserslist": [
"ie 11"
Expand Down
53 changes: 53 additions & 0 deletions packages/rum-react/src/finish-transaction-effect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* MIT License
*
* Copyright (c) 2017-present, Elasticsearch BV
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
*/

import React from 'react'
import { afterFrame } from '@elastic/apm-rum-core'

function useFinishTransactionEffect(transaction) {
/**
* React guarantees the parent component effects are run after the child components effects
* So once all the child components effects are run, we run the detectFinish logic
* which ensures if the transaction can be completed or not.
*/
React.useEffect(() => {
afterFrame(() => {
transaction && transaction.detectFinish()
})
return () => {
/**
* Incase the transaction is never ended, we check if the transaction
* can be closed during unmount phase
*
* We call detectFinish instead of forcefully ending the transaction
* since it could be a redirect route and we might prematurely close
* the currently running transaction
*/
transaction && transaction.detectFinish()
}
}, [])
}

export { useFinishTransactionEffect }
86 changes: 0 additions & 86 deletions packages/rum-react/src/get-apm-route.js

This file was deleted.

Loading

0 comments on commit 401c9dd

Please sign in to comment.