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

Support SSR without error #1

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

flobacher
Copy link

No description provided.

Copy link
Owner

@Nicell Nicell left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution! I really hadn't thought of SSR; this is a great idea. I'm thinking that a new property may not be necessary, as I've written in my review. Let me know your thoughts on this.

this.addIntersectionObserver();
const animationDistance = this.direction === 'right' || this.direction === 'down' ? '-' + this.animationDistance : this.animationDistance;
(this.el.querySelector('.nice-anim') as HTMLElement).style.setProperty('--distance', animationDistance);
}
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
}
} else {
this.el.querySelector('.nice-anim').classList.add(`slide-${this.direction}`);
}

Instead of adding a new property, it may be better to just apply the "slide-{direction}" class if this.hasIOSupport is false. That way everything will still animate in the way it was originally intended, just not on intersection.

This could maybe even be extended to just a helper method instead of having it in two places in the code.

Copy link
Author

Choose a reason for hiding this comment

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

the thing is.. there are 2 different use cases...
one: u rehydrate a ssr app.. this way, the element should be opacity 0 after the ssr, so that there is no flickering
two: ssr only... the element should be visible straight away, or like with your improved version, slide in instantly.. whats your take on this?

Copy link
Author

Choose a reason for hiding this comment

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

hey since it was late for me already I was a bit quick .. so first of all.. thank you for your great component and for sharing it!!

Copy link
Owner

Choose a reason for hiding this comment

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

The question is, can we tell if it's a SSR only or a rehydration...? If we could, then handling all three situations will work great. Otherwise, we may have some issues. I'm not sure if there's a solid way to check the difference, especially if people use this component without StencilJS.

Also, requiring a property every time may be a pain for people doing SSR. Possibly a global setting could work?

Copy link
Author

Choose a reason for hiding this comment

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

I don't know of a way to tell this..
when ssring with stencil there is a prop, but I intentionally did not use this so it works with all wc-setups..
I think the standard use-case is rehydration... its also what stencil does.. thats why I left the .nice-anim as default class.. pure ssr only setups would have to set a fallbackCSSClass="" on all the <nice-anim> instances... I think thats ok, since its not the main use case...

Copy link
Owner

Choose a reason for hiding this comment

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

@flobacher I'm looking at this soon. I'll need to test out the configuration to get a feel for how it works. Would be super helpful if you could explain the way you implemented the configuration and why? It looks nice, I'd just like to hear the reasoning behind it. I still have lots to learn :)

Copy link
Owner

Choose a reason for hiding this comment

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

^ An example code piece of usage would be great.

Copy link
Author

Choose a reason for hiding this comment

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

will try to provide this asap.. I already used/tested it in a project where I use nice-anim =)

Copy link
Owner

Choose a reason for hiding this comment

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

Were you able to get that example? I do understand what this does now. Does the class persist between each NiceAnim and updates to it in plain TS? I'm unable to test this right now, but probably will tonight. Also I'm wondering if Build.isBrowser will error on something that isn't Stencil.

Copy link
Owner

Choose a reason for hiding this comment

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

@flobacher I'd like to get this merged. So I'm still unsure on if the configuration persists between all NiceAnim instances, and if having Build.isBrowser will error on a non-Stencil site. Once I have those figured out I'll be merging this finally 😄

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.

2 participants