Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 5, 2025. It is now read-only.

fix: better iframe navigation#193

Open
dummdidumm wants to merge1 commit intomain
base:main
Choose a base branch
Loading
fromfix-iframe-navigation
Open
Show file tree
Hide file tree
Changes fromall 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
60 changes: 14 additions & 46 deletionscontent/tutorial/common/src/__client.js
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,54 +15,22 @@ window.alert = (message) => {
};

window.addEventListener('message', async (e) => {
if (e.data.type === 'fetch') {
const names = e.data.names;

const transformed = await Promise.all(
names.map(async (name) => {
const res = await fetch(name);
return {
name,
code: await res.text()
};
})
);

const css_files = [];

for (const { name, code } of transformed) {
if (
name.endsWith('.svelte') &&
code.includes('svelte&type=style&lang.css')
) {
css_files.push(name + '?svelte&type=style&lang.css');
}
}

if (css_files.length > 0) {
const css_transformed = await Promise.all(
css_files.map(async (name) => {
const res = await fetch(name);
return {
name,
code: await res.text()
};
})
);

transformed.push(...css_transformed);
}

parent.postMessage(
{
type: 'fetch-result',
data: transformed
},
'*'
);
// Belts and braces against malicious messages
if (e.data.type === 'goto' && e.data.path?.startsWith('/')) {
// SvelteKit's client.js will pick this up
const a = document.createElement('a');
a.href = e.data.path;
document.firstElementChild.append(a);
a.click();
a.remove();
}
});

history.pushState = function (state, title, url) {
// Don't create a new history entry for better back/forward navigation in the parent window
history.replaceState(state, title, url);
};

function ping() {
parent.postMessage(
{
Expand DownExpand Up@@ -90,7 +58,7 @@ if (import.meta.hot) {
});
}

/**
/**
* The iframe sometimes takes focus control in ways we can't prevent
* while the editor is focussed. Refocus the editor in these cases.
*/
Expand Down
4 changes: 2 additions & 2 deletionssrc/routes/tutorial/[slug]/Output.svelte
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -213,7 +213,7 @@
if (new_path) {
ignore_path_change = true;
[history_bwd, history_fwd] = [history_bwd.slice(0, -1), [path, ...history_fwd]];
route_to(new_path);
iframe.contentWindow?.postMessage({ type: 'goto', path:new_path }, '*');
}
}

Expand All@@ -222,7 +222,7 @@
if (new_path) {
ignore_path_change = true;
[history_bwd, history_fwd] = [[...history_bwd, path], history_fwd.slice(1)];
route_to(new_path);
iframe.contentWindow?.postMessage({ type: 'goto', path:new_path }, '*');
}
}
</script>
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp