Comments (3)
Yes, it is by design.
This polyfill is not targeting to simulate web browser environment, but providing sufficient support of environment to do server-side rendering for React (vuejs, angular 2 etc) that does not rely on DOM api when rendering on server-sider.
Meanwhile there are some stuff does not need to run on server side, so their support is limited. e.g. FormData, usually FormData is used after user input, but there is no user input when rendering on server.
In React application, document
still can be used in event handler, but not in render or component lifecycle methods.
from nashorn-polyfill.
I agree that most of the time that is the case. though for us, one of the polyfills we used in our server rendered react project, (https://github.com/chrisdickinson/raf) references document object. we try to apply the polyfills before all renders and lifecycle methods, which causes a problem during initial render.
finding out a way to omit that polyfill from the server build fixes our problem, but I figured you might want to know this use-case to make a more informed decision about the design.
from nashorn-polyfill.
Thanks for sharing.
I think if doing server-side rendering, DOM related API should be ensured that they are not called in render. Otherwise the library has to be thrown away if no walkaround. The degrade approach is to check if document exists before use it.
The reason is simple: if code throws exception because of document
is undefined, then adding a fake var document = {}
does not help since the code will continue to call something like document.getElementById()
, but that function is undefined. It can go on and on, then it eventually require a full DOM API polyfill which is hard.
from nashorn-polyfill.
Related Issues (3)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from nashorn-polyfill.