From e518cbc410a3ad00f0113bd23a53fce1d86aaf86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20=C5=BBydek?= Date: Tue, 25 Oct 2022 13:34:01 +0300 Subject: [PATCH] fix: fix broken navigation when using --- __tests__/with-environment.test.tsx | 39 +++++++++++++++++++++++++++-- package.json | 3 ++- src/components/with-environment.tsx | 6 +---- yarn.lock | 20 +++++++++++++++ 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/__tests__/with-environment.test.tsx b/__tests__/with-environment.test.tsx index cbc2693..16c7dab 100644 --- a/__tests__/with-environment.test.tsx +++ b/__tests__/with-environment.test.tsx @@ -1,7 +1,9 @@ import React, { FunctionComponent } from 'react' -import { render } from '@testing-library/react' - +import { act, render } from '@testing-library/react' import { WithEnvironment } from '../src/components/with-environment' +import { Link, MemoryRouter, Route, Routes } from 'react-router-dom' +import userEvent from '@testing-library/user-event' +import { actWait } from './helpers' describe('WithEnvironment', () => { it('enhances provided element with `env` prop', () => { @@ -27,4 +29,37 @@ describe('WithEnvironment', () => { expect(container.innerHTML).toContain('hello') }) + + it('should not break navigation', async () => { + const Home = () => ( + + Go to test + + ) + + const App = () => { + return ( + + + } /> + Test page} /> + + + ) + } + + const { container } = render( + + + + ) + + act(() => { + userEvent.click(container.querySelector('#test')!) + }) + + await actWait(250) + + expect(container.innerHTML).toContain('Test page') + }) }) diff --git a/package.json b/package.json index 1f37735..f84c1b3 100644 --- a/package.json +++ b/package.json @@ -58,8 +58,8 @@ "@semantic-release/npm": "9.0.1", "@testing-library/jest-dom": "^5.16.4", "@testing-library/preact": "^3.2.2", - "@testing-library/react-hooks": "^8.0.1", "@testing-library/react": "^13.4.0", + "@testing-library/react-hooks": "^8.0.1", "@testing-library/user-event": "^14.4.3", "@types/jest": "^27.4.0", "@types/react": "^17.0.39", @@ -84,6 +84,7 @@ "prettier": "^2.7.1", "react": "^18.2.0", "react-dom": "^18.2.0", + "react-router-dom": "^6.4.2", "rollup": "^2.75.7", "rollup-plugin-dts": "^4.2.2", "rollup-plugin-license": "^2.8.1", diff --git a/src/components/with-environment.tsx b/src/components/with-environment.tsx index ae3f843..eb9e7c2 100644 --- a/src/components/with-environment.tsx +++ b/src/components/with-environment.tsx @@ -1,4 +1,4 @@ -import { Component, cloneElement } from 'react' +import { cloneElement, Component } from 'react' import { getEnvironment } from '../get-env' import { type DetectEnvParams } from '../detect-env' @@ -44,10 +44,6 @@ class WithEnvironment extends Component { // passes the `env` down as a prop return cloneElement(this.props.children, { env: this.detectedEnv }) } - - shouldComponentUpdate() { - return false - } } export { WithEnvironment } diff --git a/yarn.lock b/yarn.lock index e4858c7..165fb7e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1217,6 +1217,11 @@ dependencies: "@octokit/openapi-types" "^12.4.0" +"@remix-run/router@1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@remix-run/router/-/router-1.0.2.tgz#1c17eadb2fa77f80a796ad5ea9bf108e6993ef06" + integrity sha512-GRSOFhJzjGN+d4sKHTMSvNeUPoZiDHWmRnXfzaxrqe7dE/Nzlc8BiMSJdLDESZlndM7jIUrZ/F4yWqVYlI0rwQ== + "@rollup/plugin-json@^4.1.0": version "4.1.0" resolved "https://registry.yarnpkg.com/@rollup/plugin-json/-/plugin-json-4.1.0.tgz#54e09867ae6963c593844d8bd7a9c718294496f3" @@ -6667,6 +6672,21 @@ react-is@^17.0.1: resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== +react-router-dom@^6.4.2: + version "6.4.2" + resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-6.4.2.tgz#115b37d501d6d8ac870683694978c51c43e6c0d2" + integrity sha512-yM1kjoTkpfjgczPrcyWrp+OuQMyB1WleICiiGfstnQYo/S8hPEEnVjr/RdmlH6yKK4Tnj1UGXFSa7uwAtmDoLQ== + dependencies: + "@remix-run/router" "1.0.2" + react-router "6.4.2" + +react-router@6.4.2: + version "6.4.2" + resolved "https://registry.yarnpkg.com/react-router/-/react-router-6.4.2.tgz#300628ee9ed81b8ef1597b5cb98b474efe9779b8" + integrity sha512-Rb0BAX9KHhVzT1OKhMvCDMw776aTYM0DtkxqUBP8dNBom3mPXlfNs76JNGK8wKJ1IZEY1+WGj+cvZxHVk/GiKw== + dependencies: + "@remix-run/router" "1.0.2" + react@^18.2.0: version "18.2.0" resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"