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

Error using ReactDiffView in Remix App #43

Open
guepjo opened this issue Apr 22, 2024 · 7 comments
Open

Error using ReactDiffView in Remix App #43

guepjo opened this issue Apr 22, 2024 · 7 comments
Labels
bug Something isn't working

Comments

@guepjo
Copy link

guepjo commented Apr 22, 2024

Summary

I am running into an error when trying to use this library

import ReactDiffViewer from "react-diff-viewer-continued";

export const DiffExpandView = () => {
	return (
		<>
			<ReactDiffViewer
				oldValue={"sourceVersion"}
				newValue={"newVersion"}
				splitView={true}
				// linesOffset={5}
			/>
		</>
	);
}

Here is the error I get:

Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

Context

I am working with a remix-react app.

Any idea how to fix this? This component would really fit my current needs so I would love to be able to use it

@ObaidAshiq
Copy link

i think your data might be an object, supposedly either sourceVersion or newVersion,
Which should have been string , mind checking these values or sharing them ?

@guepjo
Copy link
Author

guepjo commented Apr 23, 2024

@ObaidAshiq I have updated it to remove the curly braces, but it still doesn't work

import ReactDiffViewer from "react-diff-viewer-continued";

export const DiffExpandView = () => {
	return (
		<>
			<ReactDiffViewer
				oldValue="source Version" <-- removed curly braces
				newValue="new Version"  <-- removed curly braces
				splitView={true}
				// linesOffset={5}
			/>
		</>
	);
}

@guepjo guepjo changed the title Error using ReactDiffView Error using ReactDiffView in Remix App Apr 23, 2024
@Aeolun
Copy link
Owner

Aeolun commented Apr 30, 2024

I assume it has something to do with SSR somehow, but not quite sure what that would be. I'll have to boot it in a Remix app to see what effect it has.

@Aeolun Aeolun added the bug Something isn't working label Apr 30, 2024
@davidalejandroaguilar
Copy link

This also happens with a basic InertiaJS + Vite using SSR https://inertia-rails.netlify.app/guide/. The component fails during SSR, and then renders correctly on the client.

Pretty tired at the moment to create a basic reproduction app, but hoping to do one soon.

@SeungheonOh
Copy link

Somehow browser and node is loading module differently. In node(server), if I print

import ReactDiffViewer from "react-diff-viewer-continued";
console.log(ReactDiffViewer)

I get

{
  LineNumberPrefix: { LEFT: 'L', RIGHT: 'R' },
  DiffMethod: [Getter],
  default: [class DiffViewer extends Component] {
    defaultProps: {
      oldValue: '',
      newValue: '',
      splitView: true,
      highlightLines: [],
      disableWordDiff: false,
      compareMethod: 'diffChars',
      styles: {},
      hideLineNumbers: false,
      hideMarkers: false,
      extraLinesSurroundingDiff: 3,
      showDiffOnly: true,
      useDarkTheme: false,
      linesOffset: 0,
      nonce: ''
    }
  }
}

but in browser

class extends React.Component {
      constructor(props) {
        super(props);
        this.resetCodeBlocks = () => {
          if (this.state.expandedBlocks.length > 0) {
            this.setState({
   …

@SeungheonOh
Copy link

I fixed my issue by doing:

import RDV from 'react-diff-viewer-continued'
let ReactDiffViewer
if(typeof window == 'undefined') ReactDiffViewer = RDV.default
else ReactDiffViewer = RDV

@itzhoujun
Copy link

how to fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants