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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix Cannot read properties of null (reading 'getAttribute') #7930

Merged
merged 5 commits into from Dec 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/chatty-mice-tan.md
@@ -0,0 +1,5 @@
---
'@sveltejs/kit': minor
---

Checks that element is not null before reading getAttribute
2 changes: 1 addition & 1 deletion packages/kit/src/runtime/client/utils.js
Expand Up @@ -153,7 +153,7 @@ export function get_router_options(element) {
/** @type {Element} */
let el = element;

while (el !== document.documentElement) {
while (el && el !== document.documentElement) {
if (preload_code === null) preload_code = link_option(el, 'preload-code');
if (preload_data === null) preload_data = link_option(el, 'preload-data');
if (noscroll === null) noscroll = link_option(el, 'noscroll');
Expand Down
Expand Up @@ -8,6 +8,8 @@

{#if visible}
<button on:click={toggle}>remove</button>
<a on:click={toggle}>remove</a>
{:else}
<button on:click={toggle}>add</button>
<a on:click={toggle}>add</a>
{/if}
4 changes: 4 additions & 0 deletions packages/kit/test/apps/basics/test/client.test.js
Expand Up @@ -1200,6 +1200,10 @@ test.describe('Interactivity', () => {

await page.click('button');
expect(await page.textContent('button')).toBe('add');
expect(await page.textContent('a')).toBe('add');

await page.click('a');
expect(await page.textContent('a')).toBe('remove');

expect(errored).toBe(false);
});
Expand Down