Skip to content

Make $$schema stable across module reloads#101

Open
agcty wants to merge 1 commit intodmonad:mainfrom
agcty:codex/fix-schema-reload
Open

Make $$schema stable across module reloads#101
agcty wants to merge 1 commit intodmonad:mainfrom
agcty:codex/fix-schema-reload

Conversation

@agcty
Copy link

@agcty agcty commented Mar 18, 2026

Fixes #100.

Summary

  • make $$schema accept schemas created before a module reload
  • add a regression test that imports schema.js twice via distinct module URLs
  • keep the fix local to schema recognition without changing the global schema cache

Why this approach

schemaStore is global, so $type("...") can return a schema instance created by an earlier evaluation of schema.js.
After a module reload, that cached schema no longer passes instanceof Schema against the new constructor, which causes $() / $union(...) to throw Unexpected case.

This patch makes schema recognition reload-stable by adding a global symbol marker to Schema.prototype and accepting that marker in $$schema in addition to instanceof Schema.

A broader redesign around branding all schema objects more explicitly may also make sense, but that would be a larger architectural change. This PR keeps the fix minimal and targeted to the actual reload mismatch.

Verification

  • node --unhandled-rejections=strict ./src/test.js --filter 'schema: schema reload stability'
  • npx standard src/schema.js src/schema.test.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

$$schema breaks across module reloads because cached schemas fail instanceof Schema

1 participant