Conversation
- make webpack-dash-dynamic-import es5
- no polyfills in build
| { | ||
| "name": "@plotly/webpack-dash-dynamic-import", | ||
| "version": "1.1.2", | ||
| "version": "1.1.3", |
There was a problem hiding this comment.
Need a new version. The other PRs are using a rc release 1.1.3-rc1
| const srcFragments = src.split('/'); | ||
| const fileFragments = srcFragments.slice(-1)[0].split('.'); | ||
| var srcFragments = src.split('/'); | ||
| var fileFragments = srcFragments.slice(-1)[0].split('.'); |
There was a problem hiding this comment.
Use only ES5 syntax. This will be validated in the end by es-check
| corejs: 3 | ||
| }], '@babel/preset-react'], | ||
| presets: [ | ||
| '@babel/preset-env', |
There was a problem hiding this comment.
The polyfills are externalized. We only use preset-env to know what the transpilation target is.
| "prop-types@$proptypes.min.js", | ||
| ], | ||
| "dev": [ | ||
| "polyfill@$polyfill.min.js", |
There was a problem hiding this comment.
Externalized polyfills, to be used by all components
| "build:dev": "webpack --build local", | ||
| "build:local": "renderer build local", | ||
| "build": "renderer build", | ||
| "postbuild": "es-check es5 dash_renderer/*.js", |
There was a problem hiding this comment.
postbuild check, automagically runs after build
dash-renderer/webpack.config.js
Outdated
| { | ||
| test: /\.js$/, | ||
| exclude: /node_modules/, | ||
| exclude: /node_modules\/(?!@plotly\/dash-component-plugins\/|uniqid\/|check-prop-types\/)/, |
There was a problem hiding this comment.
Exclude all that can be excluded. In this case it means that @plotly/dash-component-plugins, uniqid and check-propstypes` need to be transpiled to the correct target b/c we're using the source or a dist with a less stringent target.
| } | ||
| for name, subfolder, filename, target in self.deps_info: | ||
| version = self.deps[name]["version"] | ||
| for scope, name, subfolder, filename, target in self.deps_info: |
There was a problem hiding this comment.
Handle scoped packages with @SCOPE/NAME format
| ("react-dom", "umd", "react-dom.development.js", None), | ||
| ("prop-types", None, "prop-types.min.js", None), | ||
| ("prop-types", None, "prop-types.js", None), | ||
| ("@babel", "polyfill", "dist", "polyfill.min.js", None), |
There was a problem hiding this comment.
Add polyfill, add None scope for all other deps
| @@ -0,0 +1 @@ | |||
| import '@babel/polyfill'; No newline at end of file | |||
There was a problem hiding this comment.
jest now needs the polyfills..
There was a problem hiding this comment.
seems fine, but I'm surprised jest is running in an environment that needs polyfills.
There was a problem hiding this comment.
rephrasing: jest needs the polyfills to handle our code!
alexcjohnson
left a comment
There was a problem hiding this comment.
💃 This all looks good. Now to the ⛰ of other PRs...
- bump usage / remove from webpack exclusion override
| { | ||
| test: /\.js$/, | ||
| exclude: /node_modules\/(?!@plotly\/dash-component-plugins\/|uniqid\/|check-prop-types\/)/, | ||
| exclude: /node_modules\/(?!uniqid\/|check-prop-types\/)/, |
| jsonpScriptSrc = function(chunkId) { | ||
| let script = getCurrentScript(); | ||
| let isLocal = isLocalScript(script); | ||
| if (typeof jsonpScriptSrc !== 'undefined') { |
There was a problem hiding this comment.
jsonpScriptSrc is not defined if there are no async resources, the typeof ... === 'undefined' check is the only way in JS to test for the existence/non-existence of a variable in a safe way.
| this.setProps = this.setProps.bind(this); | ||
| } | ||
|
|
||
| setProps(newProps) { |
There was a problem hiding this comment.
We were creating new setProps on each TreeContainer render. Everything in here is dependent on the injected props, it can be reused if the instance is reused. Should reduce the number of re-renders, if nothing else.
|
|
||
| /** | ||
| * This code is injected as-is in the webpack artifact and must be ES5 compatible to work in all scenarios. | ||
| * This will not get transpiled. |
There was a problem hiding this comment.
Just to note, because I was curious: it doesn't get transpiled, but it does get minified in the pipeline you've got set up - as we would hope 🎉
Related to #1003 and actually solves the issue with additional PRs (will be linked)
Also fixes #1011.
The latest async changes and following tests uncovered that Dash is broken for IE11 / Edge < 15. This comes from many things:
@plotly/dash-component-pluginswas not transpiled when used in projects@plolty/webpack-dash-dynamic-importwas not ES5 (can't be transpiled, because added directly to the webpack artifact)core-jsor@babel/polyfill. Even with correctly transpiled code they would not have workedmainin package.json -- combined with standard webpack settings excludingnode_modulesthis caused this code not to be transpiled, or (2) transpiled npm resources not transpiled in ES5, or (3) npm resources withdistbut withmainstill pointing to the sourceHandling source code from 3rd parties as part of your build process is complicated.. maybe your configuration is not compatible, or maybe the code uses another scheme (e.g.
import/exportvs.requiredvs.module.exports). Themodule.exportscase turned out to be problematic for certain 3rd parties because ofcore-js+useBuiltIns: usageside-effects, namely,the code evals everything to commonjs, wrappingmodule.exportsin a particular way that is almost but not quite normalmodule.exportsusage in Node.This PR and the attached PRs solves all of the above in 3 ways.
es-check, making it impossible to get a successful build with hanging ES6+ syntaxreact,react-dom, andprop-types-- this removes the responsibility from the component developer's hands.. making for less chances of mistakes.. a component developer can still continue using their own polyfills if some additional specifics are neededdist(or whatever) artifact -- this is time consuming as the webpackexcludeneeds to be tweaked manually (this is mostly not an issue) -- or aaliasis provided to use adistinstead of the source if the project was not setup correctly..Not covered here is whether the code actually runs in IE11 / Edge < 15, but it establishes a good baseline with rapid (build-time) feedback. Further steps would involve setting up a test environment on (say) the docs with IE11 or the oldest version of Edge available.
Also, this version of Dash will become the minimal version required for all components that are dropping
@babel/polyfillorcore-jsfrom their build -- effectively, will make this version of Dash the minimal version for all core repos, bio, canvas, cytoscape, daq.Interesting side-effect, externalizing polyfills will reduce the JS size for core (renderer, html, dcc, table) by about 70kB and the externalized polyfill can be cached / will probably be stable through multiple releases or 7% of the current minimal JS load.
Other PRs will need to update
@plotly/webpack-dash-dynamic-importto1.1.3when approved / published and some will require a version bump.