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

"Uncaught Error: Function components cannot have string refs" when adding a "?ref=xyz" param to the base url #5497

Closed
ronatory opened this issue May 10, 2022 · 9 comments · Fixed by #5537
Assignees
Labels
bug/confirmed We have confirmed this is a bug topic/router-&-navigation

Comments

@ronatory
Copy link

ronatory commented May 10, 2022

Seems to be easy reproducible. Just create a new redwood project and start the dev server via yarn rw dev and then add to the base url a ref parameter like this -> http://localhost:8910?ref=example. Then the error in the title will occur -> Uncaught Error: Function components cannot have string refs

@KrisCoulson
Copy link
Contributor

I just took a look into it.

I think we spread all the params and ref is being passed as a string

const allParams = { ...searchParams, ...pathParams }

return <Page {...allParams} />

@jtoar jtoar added this to Main May 11, 2022
@jtoar jtoar moved this to Triage in Main May 11, 2022
@jtoar jtoar self-assigned this May 11, 2022
@jtoar jtoar moved this from Triage to In Progress in Main May 11, 2022
@jtoar jtoar moved this from In Progress to Triage in Main May 11, 2022
@jtoar jtoar moved this from Triage to In Progress in Main May 11, 2022
@jtoar jtoar moved this from In Progress to Triage in Main May 11, 2022
@jtoar jtoar moved this from Triage to In Progress in Main May 11, 2022
@jtoar
Copy link
Contributor

jtoar commented May 12, 2022

@KrisCoulson Nice, that looks like what's happening indeed. I haven't thought about it much yet, but a solution that comes immediately to mind is renaming ref to something else. Is that too superficial?

@jtoar jtoar added topic/router-&-navigation bug/confirmed We have confirmed this is a bug and removed topic/router-&-navigation bug/confirmed We have confirmed this is a bug labels May 12, 2022
@jtoar jtoar removed this from Main May 14, 2022
@jtoar jtoar added this to Main May 14, 2022
@jtoar jtoar moved this to Triage in Main May 14, 2022
@jtoar jtoar removed this from Main May 14, 2022
@jtoar jtoar added this to Main May 14, 2022
@jtoar jtoar moved this to Triage in Main May 14, 2022
@jtoar jtoar removed this from Main May 14, 2022
@jtoar jtoar added this to Main May 14, 2022
@jtoar jtoar moved this to Triage in Main May 14, 2022
@jtoar jtoar removed this from Main May 14, 2022
@arioberek
Copy link

Same error here, running in production environment. In my case I can't control this URL param, it's inserted right after it's accessed from other URL, is there a workaround for this scenario?

@jtoar
Copy link
Contributor

jtoar commented Aug 29, 2022

@arrbrk1 I'll prioritize getting feedback on #5537, in the meantime, your best option is to use yarn patch to update the dist file. You can watch me do it in this video:

ref-patch.mp4

Or read along below. In your Redwood project:

yarn patch @redwoodjs/router
# ...
code /the/path/yarn/gave/you

Once you've opened the directory yarn gave you, navigate to the utils.js file. Replace that file with this one: https://gist.github.com/jtoar/06d45adcec70a12a2cafbe09ee4dbb01. Then run:

yarn patch-commit -s /the/path/yarn/gave/you

Very important: make sure all versions of your redwoodjs packages are pinned to v2.2.3 (or whatever version you're using). Pinned means no caret (^). Then:

yarn install
git add .
git commit -m "patch router"

Make sure it's fixed locally, then redeploy. (And when the patch comes out, undo all of that.)

@arioberek
Copy link

It worked, thank you! :)

@jtoar
Copy link
Contributor

jtoar commented Sep 8, 2022

@arrbrk1 the patch with the fix just went out: https://github.com/redwoodjs/redwood/releases/tag/v2.2.4. When you upgrade be sure to get rid of the yarn patch file, or at least change the resolution so that it's just 2.2.4.

@ronatory
Copy link
Author

ronatory commented Sep 20, 2022

Hello @jtoar I just upgraded to v3.0.0 and the error still occurs when doing the same steps as written in my first comment

@Tobbe
Copy link
Member

Tobbe commented Sep 20, 2022

@ronatory I tried to reproduce, but I couldn't.

image

Seems to work fine.

Just had to do yarn create redwood-app and then yarn rw dev, right?

@ronatory
Copy link
Author

@Tobbe thanks for checking. I just didn't upgraded correctly to v3.0.0. Now I did and everything works fine 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug/confirmed We have confirmed this is a bug topic/router-&-navigation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants