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

crash on import from React #1428

Closed
LXEz opened this issue Dec 17, 2024 · 0 comments
Closed

crash on import from React #1428

LXEz opened this issue Dec 17, 2024 · 0 comments

Comments

@LXEz
Copy link

LXEz commented Dec 17, 2024

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch @yaireo/[email protected] for the project I'm working on.

crash on import from React,below is the detail:

TypeError: (0 , react_compat_layer__WEBPACK_IMPORTED_MODULE_1_.memo) is not a function
at eval (webpack-internal:///(app-pages-browser)/./node_modules/@yaireo/tagify/src/react.tagify.jsx:419:71)
at (app-pages-browser)/./node_modules/@yaireo/tagify/src/react.tagify.jsx (http://localhost:3000/_next/static/chunks/app/file/%5BfileId%5D/page.js:160:1)
at options.factory (http://localhost:3000/_next/static/chunks/webpack.js:727:31)
at webpack_require (http://localhost:3000/_next/static/chunks/webpack.js:37:33)
at fn (http://localhost:3000/_next/static/chunks/webpack.js:384:21)
at eval (webpack-internal:///(app-pages-browser)/./src/components/ui/inpuTags.tsx:8:78)
at (app-pages-browser)/./src/components/ui/inpuTags.tsx (http://localhost:3000/_next/static/chunks/app/file/%5BfileId%5D/page.js:366:1)
at options.factory (http://localhost:3000/_next/static/chunks/webpack.js:727:31)
at webpack_require (http://localhost:3000/_next/static/chunks/webpack.js:37:33)
at fn (http://localhost:3000/_next/static/chunks/webpack.js:384:21)
at eval (webpack-internal:///(app-pages-browser)/./src/components/files/viewAndEdit/markdownHeader.tsx:8:81)
at (app-pages-browser)/./src/components/files/viewAndEdit/markdownHeader.tsx (http://localhost:3000/_next/static/chunks/app/file/%5BfileId%5D/page.js:333:1)
at options.factory (http://localhost:3000/_next/static/chunks/webpack.js:727:31)
at webpack_require (http://localhost:3000/_next/static/chunks/webpack.js:37:33)
at fn (http://localhost:3000/_next/static/chunks/webpack.js:384:21)
at eval (webpack-internal:///(app-pages-browser)/./src/app/file/[fileId]/page.tsx:12:102)
at (app-pages-browser)/./src/app/file/[fileId]/page.tsx (http://localhost:3000/_next/static/chunks/app/file/%5BfileId%5D/page.js:300:1)
at options.factory (http://localhost:3000/_next/static/chunks/webpack.js:727:31)
at webpack_require (http://localhost:3000/_next/static/chunks/webpack.js:37:33)
at Function.fn (http://localhost:3000/_next/static/chunks/webpack.js:384:21)

Here is the diff that solved my problem:

diff --git a/node_modules/@yaireo/tagify/src/react.tagify.jsx b/node_modules/@yaireo/tagify/src/react.tagify.jsx
index cb78188..f78b106 100644
--- a/node_modules/@yaireo/tagify/src/react.tagify.jsx
+++ b/node_modules/@yaireo/tagify/src/react.tagify.jsx
@@ -1,8 +1,9 @@
 'use client';
 
-import React, {memo, useMemo, useEffect, useRef, useCallback, renderToStaticMarkup} from './react-compat-layer'
+import React, { renderToStaticMarkup} from './react-compat-layer'
 // import {renderToStaticMarkup} from "react-dom/server"
 // import {string, array, func, bool, object, oneOfType} from "prop-types"
+import { memo, useMemo, useEffect, useRef, useCallback } from "react";
 import Tagify from "./tagify.js"
 
 const noop = _ => _
@@ -25,7 +26,7 @@ function templatesToString(templates) {
 }
 
 // used for `className` prop changes
-function compareStrings(str1, str2) {
+function compareStrings(str1 = "", str2 = "") {
     if( typeof str1 != typeof str2) return;
     const words1 = str1.split(' ');
     const words2 = str2.split(' ');
@@ -174,10 +175,14 @@ const TagifyWrapper = ({
         if (mountedRef.current) {
             // compare last `className` prop with current `className` prop and find
             // which clases should be added and which should be removed:
-            const { added, removed } = compareStrings(lastClassNameRef.current, className);
+            try {
+                const { added, removed } = compareStrings(lastClassNameRef.current, className);
 
             added.filter(String).forEach(cls => tagify.current.toggleClass(cls, true))
             removed.filter(String).forEach(cls => tagify.current.toggleClass(cls, false))
+            } catch (error) {
+                console.error("Error in compareStrings:", error);
+            }
 
         }
         // save current `className` prop for next change iteration

This issue body was partially generated by patch-package.

@yairEO yairEO closed this as completed in 108c6bc Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant