-
Notifications
You must be signed in to change notification settings - Fork 13.4k
fix(content): prevent forceUpdate in SSR #27440
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| import type { ComponentInterface, EventEmitter } from '@stencil/core'; | ||
| import { Component, Element, Event, Host, Listen, Method, Prop, forceUpdate, h, readTask } from '@stencil/core'; | ||
| import { Build, Component, Element, Event, Host, Listen, Method, Prop, forceUpdate, h, readTask } from '@stencil/core'; | ||
|
|
||
| import { getIonMode } from '../../global/ionic-global'; | ||
| import type { Color } from '../../interface'; | ||
|
|
@@ -172,11 +172,21 @@ export class Content implements ComponentInterface { | |
| } | ||
|
|
||
| private resize() { | ||
| if (this.fullscreen) { | ||
| readTask(() => this.readDimensions()); | ||
| } else if (this.cTop !== 0 || this.cBottom !== 0) { | ||
| this.cTop = this.cBottom = 0; | ||
| forceUpdate(this); | ||
| /** | ||
| * Only force update if the component is rendered in a browser context. | ||
| * Using `forceUpdate` in a server context with pre-rendering can lead to an infinite loop. | ||
| * The `hydrateDocument` function in `@stencil/core` will render the `ion-content`, but | ||
| * `forceUpdate` will trigger another render, locking up the server. | ||
| * | ||
| * TODO: Remove if STENCIL-834 determines Stencil will account for this. | ||
| */ | ||
| if (Build.isBrowser) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And so I understand, this is to work around a stencil bug correct?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't a workaround per-say. The reported issues attached are resolved by this change. I had some discussions with Tanner around if The problem that was occurring is that the pre-rendering logic would attempt to mock
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks! Can we include this context in the comment too?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also if there's an open stencil issue it would be good to link to that in the comment
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added some extra context + created a spike in JIRA for Stencil to track (and referenced it in the code comments). |
||
| if (this.fullscreen) { | ||
| readTask(() => this.readDimensions()); | ||
| } else if (this.cTop !== 0 || this.cBottom !== 0) { | ||
| this.cTop = this.cBottom = 0; | ||
| forceUpdate(this); | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.