-
Notifications
You must be signed in to change notification settings - Fork 8
RDEV-8923 - Ensure Inner Views are Disposed #211
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
Open
heldergoncalves92
wants to merge
22
commits into
master
Choose a base branch
from
RDEV-8923-ensure-inner-views-are-disposed
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
3680069
Setup Sample App
heldergoncalves92 94cea36
Update TaskListView.tsx
heldergoncalves92 36dccd1
Update TaskListView.tsx
heldergoncalves92 b74b077
Update MainView.tsx
heldergoncalves92 7ca088c
First version
heldergoncalves92 2a10ed2
Remove console log
heldergoncalves92 9a4c4f7
Send FT to View
heldergoncalves92 5dad99b
Update ReactViewFactory.cs
heldergoncalves92 a4aebcf
Add legacy files again
heldergoncalves92 c1086a0
Update ViewPortalsCollections.tsx
heldergoncalves92 d1dbbb0
Update ViewPortalsCollectionsLegacy.tsx
heldergoncalves92 ac39aad
Update ViewPortalLegacy.tsx
heldergoncalves92 4e0bc1b
Update Loader.View.tsx
heldergoncalves92 bc75cd2
Update Loader.View.tsx
heldergoncalves92 49066cf
Update Loader.View.tsx
heldergoncalves92 95e7c56
Update Loader.View.tsx
heldergoncalves92 2cc5e83
Update Loader.View.tsx
heldergoncalves92 62afa92
Update ViewMetadataContext.ts
heldergoncalves92 14f9b98
d
heldergoncalves92 73aba24
Update ViewPortal.tsx
heldergoncalves92 e3d093c
Update ReactViewFactory.cs
heldergoncalves92 5e7e9ae
r
heldergoncalves92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,14 @@ | ||
| import * as React from "react"; | ||
| import { ViewMetadata } from "./ViewMetadata"; | ||
|
|
||
| export const ViewMetadataContext = React.createContext<ViewMetadata>(null!); | ||
| const EnsureDisposeInnerViewsFlagKey = "ENSURE_DISPOSE_INNER_VIEWS"; | ||
|
|
||
| export const ViewMetadataContext = React.createContext<ViewMetadata>(null!); | ||
|
|
||
| export function getEnsureDisposeInnerViewsFlag(): boolean { | ||
| return !!window[EnsureDisposeInnerViewsFlagKey]; | ||
| } | ||
|
|
||
| export function setEnsureDisposeInnerViewsFlag(ensureDisposeInnerViews: boolean): void { | ||
| window[EnsureDisposeInnerViewsFlagKey] = ensureDisposeInnerViews; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| import * as React from "react"; | ||
| import { webViewRootId } from "../Internal/Environment"; | ||
| import { getStylesheets } from "./Common"; | ||
| import { ViewMetadata } from "./ViewMetadata"; | ||
| import { ViewSharedContext } from "../Public/ViewSharedContext"; | ||
|
|
||
| export type ViewLifecycleEventHandler = (view: ViewMetadata) => void; | ||
| export type ViewErrorHandler = (view: ViewMetadata, error: Error) => void; | ||
|
|
||
| export interface IViewPortalProps { | ||
| view: ViewMetadata | ||
| viewMounted: ViewLifecycleEventHandler; | ||
| viewUnmounted: ViewLifecycleEventHandler; | ||
| viewErrorRaised: ViewErrorHandler; | ||
| } | ||
|
|
||
| interface IViewPortalState { | ||
| component: React.ReactElement; | ||
| } | ||
|
|
||
| /** | ||
| * A ViewPortal is were a view is rendered. The view DOM is then moved into the appropriate placeholder. | ||
| * This way we avoid a view being recreated (and losing state) when its ViewFrame is moved in the tree. | ||
| * | ||
| * A View Frame notifies its sibling view collection when a new instance is mounted. | ||
| * Upon mount, a View Portal is created and it will be responsible for rendering its view component in the shadow dom. | ||
| * A view portal is persisted until its View Frame counterpart disappears. | ||
| * */ | ||
| export class ViewPortalLegacy extends React.Component<IViewPortalProps, IViewPortalState> { | ||
|
|
||
| private head: Element; | ||
| private shadowRoot: HTMLElement; | ||
|
|
||
| constructor(props: IViewPortalProps, context: any) { | ||
| super(props, context); | ||
|
|
||
| this.state = { component: null! }; | ||
|
|
||
| this.shadowRoot = props.view.placeholder.attachShadow({ mode: "open" }).getRootNode() as HTMLElement; | ||
|
|
||
| props.view.renderHandler = component => this.renderPortal(component); | ||
| } | ||
|
|
||
| private renderPortal(component: React.ReactElement) { | ||
| const wrappedComponent = ( | ||
| <ViewSharedContext.Provider value={this.props.view.context}> | ||
| {component} | ||
| </ViewSharedContext.Provider> | ||
| ); | ||
| return new Promise<void>(resolve => this.setState({ component: wrappedComponent }, resolve)); | ||
| } | ||
|
|
||
| public shouldComponentUpdate(nextProps: IViewPortalProps, nextState: IViewPortalState) { | ||
| // only update if the component was set (once) | ||
| return this.state.component === null && nextState.component !== this.state.component; | ||
| } | ||
|
|
||
| public componentDidMount() { | ||
| this.props.view.head = this.head; | ||
|
|
||
| const styleResets = document.createElement("style"); | ||
| styleResets.innerHTML = ":host { all: initial; display: block; }"; | ||
|
|
||
| this.head.appendChild(styleResets); | ||
|
|
||
| // get sticky stylesheets | ||
| const stylesheets = getStylesheets(document.head).filter(s => s.dataset.sticky === "true"); | ||
| stylesheets.forEach(s => this.head.appendChild(document.importNode(s, true))); | ||
|
|
||
| this.props.viewMounted(this.props.view); | ||
| } | ||
|
|
||
| public componentWillUnmount() { | ||
| this.props.viewUnmounted(this.props.view); | ||
| } | ||
|
|
||
| public componentDidCatch(error: Error, errorInfo: React.ErrorInfo) { | ||
| // execute error handling inside promise, to avoid the error handler to rethrow exception inside componentDidCatch | ||
| Promise.resolve(null).then(() => this.props.viewErrorRaised(this.props.view, error)); | ||
| } | ||
|
|
||
| public render(): React.ReactNode { | ||
| return ReactDOM.createPortal( | ||
| <> | ||
| <head ref={e => this.head = e!}> | ||
| </head> | ||
| <body> | ||
| <div id={webViewRootId} ref={e => this.props.view.root = e!}> | ||
| {this.state.component ? this.state.component : null} | ||
| </div> | ||
| </body> | ||
| </>, | ||
| this.shadowRoot); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,6 +11,7 @@ import { Task } from "./Internal/Task"; | |
| import { ViewMetadata } from "./Internal/ViewMetadata"; | ||
| import { createPropertiesProxy } from "./Internal/ViewPropertiesProxy"; | ||
| import { addView, getView, tryGetView } from "./Internal/ViewsCollection"; | ||
| import { setEnsureDisposeInnerViewsFlag } from "./Internal/ViewMetadataContext"; | ||
|
|
||
| export { disableMouseInteractions, enableMouseInteractions } from "./Internal/InputManager"; | ||
| export { showErrorMessage } from "./Internal/MessagesProvider"; | ||
|
|
@@ -126,7 +127,8 @@ export function loadComponent( | |
| hasPlugins: boolean, | ||
| componentNativeObject: any, | ||
| frameName: string, | ||
| componentHash: string): void { | ||
| componentHash: string, | ||
| ensureDisposeInnerViews: boolean): void { | ||
|
|
||
| async function innerLoad() { | ||
| let view: ViewMetadata; | ||
|
|
@@ -135,6 +137,11 @@ export function loadComponent( | |
| // wait for the stylesheet to load before first render | ||
| await defaultStylesheetLoadTask.promise; | ||
| } | ||
|
|
||
| if (frameName === mainFrameName) { | ||
| console.log(`Set ensureDisposeInnerViewsFlag to ${ensureDisposeInnerViews} for main frame`); | ||
|
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. to be removed? |
||
| setEnsureDisposeInnerViewsFlag(ensureDisposeInnerViews); | ||
| } | ||
|
|
||
| view = tryGetView(frameName)!; | ||
| if (!view) { | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
extra line break to remove