Skip to content
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]: Uncaught TypeError: Cannot destructure property 'basename' of 'React.useContext(...)' as it is null. #11237

Closed
kadiyamsuresh opened this issue Jan 31, 2024 · 3 comments
Labels

Comments

@kadiyamsuresh
Copy link

What version of React Router are you using?

6

Steps to Reproduce

Hi Team,

This issue is in continuation to #11162

I have created an application in codesandbox with our components library which contains wrapper of all the standard components like Link. Link component of react-router-dom v6 is breaking the application, getting the below error in console.

To reproduce issue, see below URL.
codesandbox URL: https://codesandbox.io/p/devbox/tsc8ph?file=%2Fpackage.json%3A26%2C27

image

Expected Behavior

Link component from React-router-dom v6 should work.

Actual Behavior

Link component from React-router-dom v6 is breaking application

@brophdawg11
Copy link
Contributor

It looks like you have inlined all of React Router into your component library file, which is where the duplicate contexts are coming from. In componentsLibrary/index.esm.jsx, these chunks of code should not be inlined and should come from a react-router-dom import:

const NavigationContext = /*#__PURE__*/React.createContext(null);
if (process.env.NODE_ENV !== "production") {
  NavigationContext.displayName = "Navigation";
}
....
function useHref(to, _temp) { ... }
...
const Link = /*#__PURE__*/React.forwardRef(function LinkWithRef(_ref7, ref) { ... }

@brophdawg11 brophdawg11 closed this as not planned Won't fix, can't repro, duplicate, stale Jan 31, 2024
@khaledtag98
Copy link

Any workaround available to share the same Router instance between application and library?

@sureshsumtotal
Copy link

sureshsumtotal commented Aug 8, 2024

To maintain same instance for both places we need to update package.json file in library repository.

Should add “react-router-dom” library under “peerDependencies” section.

Should not add “react-router-dom” library under “dependencies” section.

Should add “react-router-dom” library under “resolutions” section to maintain same version in both repositories.

“react-router-dom” should not be part of library bundles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants