question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Modifying `HTMLElement.prototype.focus` prevents server side rendering

See original GitHub issue

🐛 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

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
macdonstcommented, Sep 3, 2020

@devongovett This is working great in my Gatsby project so I believe you can close this bug.

2reactions
icarapscommented, Sep 3, 2020

@devongovett Thanks for the latest release with SSR support !

Read more comments on GitHub >

github_iconTop Results From Across the Web

The Case for Custom Elements: Part 2 | by Rob Dodson
The aforementioned frameworks can leverage server-side rendering to ensure that users at least have a workable page even if the client-side ...
Read more >
How do you automatically set the focus to a textbox when a ...
I had to either get placeholders staying cross-browser, which has weird side effects, or stop using autofocus . So I listened for the...
Read more >
Focus management with Vue refs - Learn web development
Well, remember that when we change isEditing to true , we no longer render the section of the component featuring the "Edit" button....
Read more >
Handling route changes in React, accessibly
At its simplest level, server-side rendering means that when you navigate ... the way focus is handled when that route change takes place....
Read more >
JavaScript Tutorial: The Basics
What to stop someone from writing a JavaScript that wipes out your ... To modify the content of an HTML element, you can...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found