Skip to content

Modifying HTMLElement.prototype.focus prevents server side rendering #699

@macdonst

Description

@macdonst

🐛 Bug Report

Modifying HTMLElement.prototype.focus prevents server side rendering.

I'm using Gatsby to build a site which also uses react-spectrum v3. Running the site in development works but once I do a production build an error occurs preventing the site from being built.

🤔 Expected Behavior

I hope to be able to use react-spectrum v3 with a site that is doing server side rendering. 🤞

😯 Current Behavior

Setup the reproduction scenario:

  1. Clone the reproduction repo.
  2. cd gatsby-rsv3
  3. npm i

Run the client side rendering scenario:

  1. gatsby develop

You'll be able to open localhost:8000 and see that the site is running with a @react-spectrum/button.

Screenshot 2020-07-06 15 55 39

Now run the server side scenario:

  1. gatsby clean
  2. gatsby build

This should give you an error message:

  963 |
> 964 |   let focus = HTMLElement.prototype.focus;
      | ^
  965 |
  966 |   HTMLElement.prototype.focus = function () {
  967 |     $d01f69bb2ab5f70dfd0005370a2a2cbc$var$hasEventBeforeFocus = true;


  WebpackError: ReferenceError: HTMLElement is not defined

  - module.js:964
    node_modules/@react-aria/interactions/dist/module.js:964:1

  - module.js:1018
    node_modules/@react-aria/interactions/dist/module.js:1018:1

  - module.js:392
    node_modules/@react-aria/focus/dist/module.js:392:22

  - module.js:427
    node_modules/@react-aria/focus/dist/module.js:427:4

💁 Possible Solution

If I find something I'll come back here and update.

🔦 Context

It's keeping us from switching over from react-spectrum v2 on our internal doc site: https://docs.corp.adobe.com/

💻 Code Sample

Sample repo that provides the smallest reproduction scenario I could come up with is at:

https://github.com/macdonst/gatsby-rsv3

🌍 Your Environment

Software Version(s)
react-spectrum "@react-spectrum/button": "^3.0.0", "@react-spectrum/provider": "^3.0.0", "@react-spectrum/theme-default": "^3.0.0"
Browser n/a
Operating System MacOS 10.15.5

🧢 Your Team

Adobe I/O

🕷 Tracking Issue

n/a

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingssr

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions