Skip to content

SSR Environments (.e.g Remix): window is not defined #37

@Tom-Pearce

Description

@Tom-Pearce

Hello,

We were looking to use the Drop In client in order to offer our customers an alternative after failing finance. It would have been preferable to help limit the number of times our customers are redirected away from our site throughout the checkout process (having already failed finance checks with another partner to be eligible for our GC offer).

Unfortunately as we are running a Remix front end which uses SSR, we've found that as the GC useGoCardlessDropin function is trying to access window which doesnt exist on the SSR portion of remix it causes an error. We have attempted to use a ClientOnly utility to wrap the whole component but this is unable to assist in this scenario unfortunately.

An excerpt from a colleague who assisted with my prototyping:

Looks like the useGoCardlessDropin is trying to access the window object which isn't available in SSR environments, like Remix. And as it's a hook we can't conditionally render it on our end as that breaks the "rules of hooks". I think they would likely need to add some kind of check into the hook itself that would check for the window object

Remix docs describing the issue

In the short term we will just be using the APIs to obtain a Billing Request Flow URL and redirecting our customers. In the long term we may look to implement patch-package, if GC are unable to patch this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions