Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(5.0): Refactoring navigateToUrl to reduce byte size #395

Merged
merged 3 commits into from Dec 3, 2019

Conversation

joeldenning
Copy link
Member

@joeldenning joeldenning commented Dec 1, 2019

Before:

23778 bytes - lib/esm/single-spa.min.js
23800 bytes - lib/system/single-spa.min.js
23985 bytes - lib/umd/single-spa.min.js

After:

23012 bytes - lib/esm/single-spa.min.js
23034 bytes - lib/system/single-spa.min.js
23231 bytes - lib/umd/single-spa.min.js

Two perf things here:

  1. Removed the navigateToUrl opts, and used @rollup/plugin-replace to remove the code that only exists for tests
  2. Reimplemented parseUri and navigateToUrl to use browser anchor tags instead of the 3p lib that was pasted in earlier.

@ghost
Copy link

ghost commented Dec 1, 2019

DeepCode Report (#215515)

DeepCode analyzed this pull request.
There are no new issues. 1 info report was fixed.

Copy link
Member

@frehner frehner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

two questions

singleSpaNavigate("#/route?yoshi=criminal");
spyOn(window.history, "pushState");
singleSpaNavigate("#/route?yoshi=freeanimal");
expect(location.hash).toBe("#/route?yoshi=freeanimal");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👀

return uri;
const anchor = document.createElement("a");
anchor.href = str;
return anchor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow this is quite the update

is an anchor tag the same return object shape as what was previously returned from this function?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite - path becomes pathname, etc. This accounts for the changes I made later on in the navigateToUrl function

@@ -45,6 +45,7 @@
"@babel/core": "^7.5.5",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/preset-env": "^7.5.5",
"@rollup/plugin-replace": "^2.2.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this come in addition to a change to the rollup config?

or was this just an accidental inclusion from another PR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah good catch - this is for process.env.BABEL_ENV. I made the change to the rollup config but lost it in my frantic switching between branches. Will reinstate.

Copy link
Member

@frehner frehner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐽

is this also something we could do to have dev-specific errors as well? e.g. if(dev) and have replace be dev: false?

@joeldenning
Copy link
Member Author

This technique could be used for dev/prod error messages. But I think better would be to use the technique described in https://github.com/facebook/react/tree/master/scripts/error-codes

@joeldenning joeldenning merged commit b66870e into 5.0 Dec 3, 2019
@joeldenning joeldenning deleted the navigate-to-url branch December 3, 2019 07:51
joeldenning added a commit that referenced this pull request Feb 23, 2020
* Adding prettier, speeding up pre-commit, and making clean script cross platform (#391)

* Speeding up pre-commit, and making clean script cross platform

* Adding prettier

* Upgrading nodejs version in Travis (#394)

* (5.0): Remove deprecated lifecycles (#390)

* (5.0) Improving perf with babel/rollup changes (#392)

* Improving perf with babel/rollup changes

* Upgrading travis' node version

* Removing babel-loader

* (5.0): Reducing bundle size by removing class syntax (#393)

* Avoiding classes to save bytes

* Upgrading node version in travis

* (5.0): Various refactors that improve performance (#396)

* Various refactors that improve performance

* Self review

* Self review

* (5.0): Refactoring navigateToUrl to reduce byte size (#395)

* Refactoring navigateToUrl to reduce byte size

* Anthony's feedback

* should be functionally the same as it was before. (#403)

but now with less duplication!

* Switching to error codes for production single-spa (#400)

* Switching to error codes for production single-spa

* Self review

* Self review

* Self review

* Self review

* Self review

* Self review

* Anthony's feedback

* Anthony's feedback

* (5.0): Breaking - remove err.name and err.appName from thrown errors. (#404)

* Switching to error codes for production single-spa

* Self review

* Self review

* Self review

* Self review

* Self review

* Self review

* Anthony's feedback

* Switching from name property to appOrParcelName

* Self review

* Adding support for warningMillis timeout config. Resolves #346. (#389)

* Adding support for warningMillis timeout config. Resolves #346.

* Self review

* Adding more tests, and self review

* Excluding failing tests temporarily

* Linter errors

* Self review

* Tests

* Self review

* Self review

* Fixing tests

* Uncommenting fit

* Updating link to error codes (#406)

* Switching from object rest spread to manual assign. (#401)

* Switching from object rest spread to manual assign.

* More assigns

* Self review

* Prototype pollution

* Self review

* Self review

* Small updates to parcel-related errors (#407)

* Small updates to parcel-related errors

* Self review

* v5.0.0-beta.0

* Adding banner comment to output bundles (#409)

* Adding banner comment to output bundles

* Self review

* Improving description and keywords (#410)

* v5.0.0-beta.1

* Small improvements to error messages (#423)

* Migrating references of CanopyTax org to single-spa

Co-authored-by: Anthony Frehner <frehner@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants