Skip to content

todo-pane fires HEAD <baseUrl>/null when data island has no src attribute #12

@melvincarvalho

Description

@melvincarvalho

Symptom

Console shows a 404 on every load of a LOSOS app whose data island is inline (no `src` attribute):

```
HEAD https://solid-apps.github.io/todos/null 404 (Not Found)
```

Non-blocking — the app renders fine, the URL is just garbage. But it's noise in production demos and confusing for new contributors trying to understand what the app's actually fetching.

Reproduction

Open https://solid-apps.github.io/todos/ — the Todos demo has an inline data island, no `src`. The 404 fires immediately after page load.

Root cause

In `panes/todo-pane.js` (line ~24-32 of the render() method):

```js
var dataEl = document.querySelector('script[type="application/ld+json"]')
...
var dataUrl = new URL(dataEl.getAttribute('src'), window.location.href).href
var store = createStore(data, {
url: dataUrl,
...
})
```

When the data island has no `src` attribute, `getAttribute('src')` returns `null`. The `URL` constructor stringifies the first argument, so `new URL(null, 'https://.../todos/')` produces `'https://.../todos/null'`. That non-empty string then passes the truthy guard in `store.js`:

```js
// losos/store.js:217
if (url) {
doFetch(url, { method: 'HEAD' }).then(...) // line 219 — fires the 404
}
```

…and HEAD-fires the bogus URL.

Suggested fix (in caller)

`todo-pane.js` (and any other pane doing the same pattern):

```diff

  • var dataUrl = new URL(dataEl.getAttribute('src'), window.location.href).href
  • var src = dataEl.getAttribute('src')
  • var dataUrl = src ? new URL(src, window.location.href).href : null
    ```

Then `createStore({ url: null })` triggers the existing `if (url)` guard correctly, no HEAD fires, no console noise.

`shell.js` already does the right thing — both `loadData()` and the `baseUrl` fallback in the boot path check `dataEl.getAttribute('src')` truthiness before constructing a URL. The bug is specifically in panes that re-derive `dataUrl` independently.

Worth grepping `panes/` for `new URL(dataEl.getAttribute('src')` and applying the same guard everywhere — `schema-pane.js` for example does the same construction (line ~28) and may have the same bug, just doesn't trigger HEAD because it doesn't pass `url` to `createStore`.

Belt-and-braces alternative (in callee)

Could also tighten `store.js:217`:

```diff

  • if (url) {
  • if (url && !url.endsWith('/null')) {
    ```

That's a band-aid for the symptom. The real fix is in the URL construction.

Related

  • Encountered while building https://solid-apps.github.io/todos/ — the app works fine, this is purely cosmetic console hygiene.
  • Same pattern may bite anyone writing a new bespoke pane that copies the URL-construction snippet from todo-pane.js as a template.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions