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] - TypeError: Cannot read properties of null (reading 'getValue') #189

Open
joelpierre opened this issue Oct 3, 2023 · 5 comments
Open
Assignees

Comments

@joelpierre
Copy link

Currently seeing the below, I think there may be some guard clauses missing before calling "getValue"

TypeError: Cannot read properties of null (reading 'getValue')
    at /var/task/node_modules/.pnpm/flagsmith@3.19.1/node_modules/flagsmith/react.js:1:1616
    at Array.map (<anonymous>)
    at c (/var/task/node_modules/.pnpm/flagsmith@3.19.1/node_modules/flagsmith/react.js:1:1581)
    at e.useFlags (/var/task/node_modules/.pnpm/flagsmith@3.19.1/node_modules/flagsmith/react.js:1:2458)
@novakzaballa
Copy link
Contributor

Hi @joelpierre, can you please provide more details and context about this issue, including how can we reproduce it?

@joelpierre
Copy link
Author

joelpierre commented Oct 3, 2023

Hey, it turns out it was very bespoke to our setup with server side Algolia not playing ball, however it would be great if in your SDK the useFlag hook didn't do this

const res = useMemo(() => {
        const res: any = {}
    flags.map((k) => {
        res[k] = {
                enabled: flagsmith!.hasFeature(k), // <------  non-null assertion
                value: flagsmith!.getValue(k), // <------  non-null assertion
        }
    }).concat(traits?.map((v) => {
        res[v] = flagsmith!.getTrait(v) // <------  non-null assertion
    }))

As you can see the flagsmith! which is what is blowing up for us. Not sure if you can change these to flagsmith?. ...

@kyle-ssg
Copy link
Member

kyle-ssg commented Oct 3, 2023

Hey again, I think maybe we could, however I'm not sure what cases would exist where the Flagsmith Providers don't get a Flagsmith instance. Was there a good example that I'm maybe not understanding?

@Flagsmith Flagsmith deleted a comment from dabeeeenster Oct 3, 2023
@joelpierre
Copy link
Author

With Algolia SSR they want you to do some pretty weird and wonderful things for server side rendering as you can see here: https://www.algolia.com/doc/guides/building-search-ui/going-further/server-side-rendering/react/#with-nextjs and as a result we have to pre-render the Algolia listing "stuff" server side and renderToString... in essence all our _app providers are not loaded in this serverState until hydration kicks in on the client.

It would be good if flagsmith didn't blow up though haha as I went down a rabit hole debugging it 😬 . OR if there was more of a check to ensure the provider state was set before trying to do anything further?

@novakzaballa
Copy link
Contributor

Hi there, could you please include a sample minimal project failing, and a clear description of what would be the expected behavior?

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

3 participants