This repository has been archived by the owner on May 7, 2021. It is now read-only.
[Snyk] Upgrade @jaredpalmer/after from 1.4.0 to 1.6.1 #3
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Snyk has created this PR to upgrade @jaredpalmer/after from 1.4.0 to 1.6.1.
ℹ️ Keep your dependencies up-to-date. This makes it easier to fix existing vulnerabilities and to more quickly identify and fix newly disclosed vulnerabilities when they affect your project.Release notes
Package name: @jaredpalmer/after
v1.6.0...v1.6.1
Tree Shaking 🌲
After.js is now 60KB smaller
Before:
After:
closes #238
Auto-Scroll Control 📜
Disable Auto-Scroll Globally
By default, After.js will scroll to top when URL changes, you can change that by passing
scrollToTop: false
to render().Disable Auto-Scroll for a Specific Page
We are using a ref object to minimize unnecessary re-renders, you can mutate scrollToTop.current and component will not re-rendered but its scroll behavior will change immediately.
You can control auto-scroll behavior from
getInitialProps
.closes #258
<SerializeData />
andgetSerializedData()
📃when you do SSR and you use redux, mobx, ... in
document.js
you have to pass store data to the client and on the client beforeensure ready
get called you have to read that data and put in the redux store.<SeriallizeData />
will do that for you.to get data in the client use
getSerializedData
method:getSerializedData
will read data from window object and then it will remove object from window, you can change this behavior by passing a second argument to the method:v1.5.1...v1.6.0
v1.5.0...v1.5.1
Changed
getInitialProps
BehaviorOld Behavior
URL Change -> getInitialProps get called -> matched component get renderd on screen -> getInitialProps resolved -> component gets re-renered and can acess getInitialProps data from it's props
this is very bad and there are some problems:
<Spinner />
tillgetInitialProps
resolvedgetInitialProps
resolved, so the user will see nothing (or footer) for a whilegetInitialProps
with hooks, we have to write very complicated codedata
is undefined so count is undefined, and to fix it we have to write an effect like below:New Behavior:
URL Change -> getInitialProps get called -> wait's on current location until getInitialProps resolved -> render matched component with data from getInitialProps
When a user moves from page
/a
to page/b
, URL changes but the user still sees/a
page on the screen till/b
page data get fetched.Custom
Document.js
Now we have a simpler custom Document with
<AfterScripts />
and<AfterStyles />
.Any params that passed to
getInitialProps
and return values of it are available from__AfterContext
.Use this context to build components for your custom Document.
<AfterScripts />
,<AfterStyles />
(#279) 287c7c8v1.4.0...v1.5.0
Dynamic 404 and Redirects
404 Page
React Router can detect No Match (404) Routes and show a fallback component, you can define your custom fallback component in
routes.js
file.Notfound component must set
staticContext.statusCode
to 404 so express can set response status code more info.if you don't declare 404 component in
routes.js
After.js will use its default fallback.Dynamic 404
Sometimes you may need to send a 404 response based on some API response, in this case, react-router don't show fallback and you have to check for that in your component.
this makes code unreadable and hard to maintain. after.js makes this easy by providing an API for handling Dynamic 404 pages. you can return
{ statusCode: 404 }
fromgetInitialProps
and after.js will show 404 fallback components that you defined inroutes.js
for you.Redirect
You can redirect the user to another route by using
Redirect
from react-router, but it can make your code unreadable and hard to maintain.with after.js you can redirect client to other route by returning
{ redirectTo: "/new-location" }
fromgetInitialProps
.this can become handy for authorization when user does not have permission to access a specific route and you can redirect him/her to the login page.
The redirect will happen before after.js start renders react to string soo it's fast.
when using
redirectTo
default value forstatusCode
is 301, but you can use any numeric value you want.Commits:
Note: You are seeing this because you or someone else with access to this repository has authorized Snyk to open upgrade PRs.
For more information:
🧐 View latest project report
🛠 Adjust upgrade PR settings
🔕 Ignore this dependency or unsubscribe from future upgrade PRs