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

Don't render until initial data loaded #147

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/plugin/memory-webview-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,14 @@ export class MemoryWebview implements vscode.CustomReadonlyEditorProvider {
}

// Set HTML content
await this.getWebviewContent(panel);
await this.getWebviewContent(panel, initialMemory);

// Sets up an event listener to listen for messages passed from the webview view context
// and executes code based on the message that is received
this.setWebviewMessageListener(panel, initialMemory);
}

protected async getWebviewContent(panel: vscode.WebviewPanel): Promise<void> {
protected async getWebviewContent(panel: vscode.WebviewPanel, initialMemory?: MemoryOptions): Promise<void> {
const mainUri = panel.webview.asWebviewUri(vscode.Uri.joinPath(
this.extensionUri,
'dist',
Expand All @@ -194,7 +194,7 @@ export class MemoryWebview implements vscode.CustomReadonlyEditorProvider {
<link href="${memoryInspectorCSS}" rel="stylesheet" />
</head>
<body>
<div id='root'></div>
<div id='root'></div>${initialMemory ? `<div id='initial-data' data-options='${JSON.stringify(initialMemory)}'></div>` : ''}
</body>
</html>
`;
Expand All @@ -206,7 +206,6 @@ export class MemoryWebview implements vscode.CustomReadonlyEditorProvider {
this.messenger.onNotification(readyType, async () => {
this.setSessionContext(participant, this.createContext());
await this.setMemoryDisplaySettings(participant, panel.title);
this.refresh(participant, options);
}, { sender: participant }),
this.messenger.onRequest(setOptionsType, newOptions => { options = { ...options, ...newOptions }; }, { sender: participant }),
this.messenger.onRequest(logMessageType, message => outputChannelLogger.info('[webview]:', message), { sender: participant }),
Expand Down
13 changes: 11 additions & 2 deletions src/webview/memory-webview-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,18 @@ export const DEFAULT_MEMORY_DISPLAY_CONFIGURATION: MemoryDisplaySettings = {
visibleColumns: manifest.DEFAULT_VISIBLE_COLUMNS
};

function getInitialValuesHolder(): HTMLElement | null {
return document.getElementById('initial-data');
}

class App extends React.Component<{}, MemoryAppState> {
protected memoryWidget = React.createRef<MemoryWidget>();
protected refreshTimer?: NodeJS.Timeout | number;

public constructor(props: {}) {
super(props);
const initialValuesHolder = getInitialValuesHolder();
const initialReadArguments = initialValuesHolder ? { ...DEFAULT_READ_ARGUMENTS, ...JSON.parse(initialValuesHolder.dataset['options']!) } : DEFAULT_READ_ARGUMENTS;
columnContributionService.register(new AddressColumn(), false);
columnContributionService.register(new DataColumn(), false);
columnContributionService.register(variableDecorator);
Expand All @@ -106,8 +112,8 @@ class App extends React.Component<{}, MemoryAppState> {
sessionContext: DEFAULT_SESSION_CONTEXT,
memory: undefined,
effectiveAddressLength: 0,
configuredReadArguments: DEFAULT_READ_ARGUMENTS,
activeReadArguments: DEFAULT_READ_ARGUMENTS,
configuredReadArguments: initialReadArguments,
activeReadArguments: initialReadArguments,
decorations: [],
hoverService: hoverService,
columns: columnContributionService.getColumns(),
Expand All @@ -118,6 +124,9 @@ class App extends React.Component<{}, MemoryAppState> {
}

public componentDidMount(): void {
if (getInitialValuesHolder()) {
this.fetchMemory(this.state.activeReadArguments);
}
messenger.onRequest(setOptionsType, options => this.setOptions(options));
messenger.onNotification(memoryWrittenType, writtenMemory => this.memoryWritten(writtenMemory));
messenger.onNotification(sessionContextChangedType, sessionContext => this.sessionContextChanged(sessionContext));
Expand Down
Loading