 	private func documentChanged() {
 		parsedDocument = nil
 		lastContents = nil
-		contentsDisposable?.dispose()
-		contentsDisposable = context.value?.currentDocument.value?.editedContents.signal.observeValues { [weak self] _ in
-			self?.contentsChanged()
-		}
 		updatePreview()
 	}
-	
-	/// called when the editedContexts of the current document changed
-	private func contentsChanged() {
-//		updatePreview()
-	}
+		
+	/// called when the context property has been set
+	private func contextChanged() {
+		lastContents = nil
+		parsedDocument = nil
+		curDocDisposable?.dispose()
+		curDocDisposable = editorContext?.currentDocument.signal.observeValues({ [weak self] newDoc in
+			self?.documentChanged()
+		})
+		if !resourcesExtracted {
+			ensureResourcesLoaded()
+		}
+		documentChanged()
+	}
+	
+	// MARK: - content presentation
 	
 	private func loadInitialPage() {
 		guard headerContents.count == 0 else { return }

				return
			}
		}
		guard let curDoc = parsedDocument else {
			load(html: emptyContents)
			return

		guard let contents = updatedContents ?? context.value?.currentDocument.value?.currentContents
			else { Log.warn("current doc has no contents??"); return }
		if contents == lastContents { return }
		
		// update the parsed document, update the webview
		parseInProgress = true
		defer { parseInProgress = false }
		let changedChunkIndexes = try! RmdDocument.update(document: curDoc, with: contents) ?? []
