Dev server instability / client-side CORS error during development

Open
#3,843 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
deno, typescript
Domain
devtools

Research direction

Start by tracing how the Fresh dev server emits island import paths and compare the normal and broken HTML snippets in the issue. The payload does not name relevant source files or tests, so first locate the dev server code that generates these imports and look for a way to reproduce the intermittent failure. Done means island imports keep their expected /@id/ paths and hot reload continues working after iterative development.

Written by the indexing model from the issue text.

Description

I've recently begun using Fresh for the first time, and I've been struggling a bit with the dev server stability.

After a bit of iterative work on my Fresh app, the islands suddenly break and hot reload stops working. The dev server keeps serving the latest content when I reload. Regardless, if I'm working on an island then this is a show stopper until I go back to the terminal and kill+restart deno run dev. Once I do that, everything works again for another while.

Page Error

The browser console error resembles this:

❌ Access to script at 'fresh-island::EmptyIsland.tsx' from origin 'https://[...]' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: chrome, chrome-extension, chrome-untrusted, data, http, https, isolated-app.
❌ fresh-island::EmptyIsland.tsx:1  GET fresh-island::EmptyIsland.tsx net::ERR_FAILED
Difference in emitted HTML

I've noticed that the script content in the served HTML changes when the issue occurs, normally it looks like this: (line breaks added for readability)

<script type="module" nonce="ea0a857d6094481086103eb6593c3faf">
import { boot } from "/@id/fresh:client-entry";
import EmptyIsland from "/@id/fresh-island::EmptyIsland";
boot({EmptyIsland},"[[1],{\"slots\":2,\"props\":3},[],{}]");
</script>

When the client is broken, the served HTML instead looks like this:

<script type="module" nonce="12f27aae0dad496baf9394f2d2defdb5">
import { boot } from "/@id/fresh:client-entry";
import EmptyIsland_2 from "fresh-island::EmptyIsland.tsx";
boot({EmptyIsland_2},"[[1],{\"slots\":2,\"props\":3},[],{}]");
</script>

It seems like something on the dev server is losing some context about how it should emit import paths.
(I see that the symbol name changed to include _2 in the sample, I don't know if that's always the case or for some other reason)

Previous context

I've found a previous issue which seems to have a similar symptom but a different cause, as it describes a Fresh upgrade which resulted in an app which doesn't work at all:

Dominant language
TypeScript
Stars
13.8k
Forks
757
Avg merge
3m
Merged PRs (30d)
2

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from freshframework/fresh

All issues in freshframework/fresh

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.