Skip to content

Sharing string#1

Open
lvkoppen wants to merge 3 commits into
fredppm:mainfrom
lvkoppen:sharing-string
Open

Sharing string#1
lvkoppen wants to merge 3 commits into
fredppm:mainfrom
lvkoppen:sharing-string

Conversation

@lvkoppen

@lvkoppen lvkoppen commented May 6, 2026

Copy link
Copy Markdown

Hey Fredppm,

First off, I really love this tool! It looks really clean and it makes it so much easier to plan more complex parts of my factory. But with bigger design I kept having a issue my work couldn't be saved correctly because the URL just became too long. I decided why don't I try to fix it!

I'm not super experienced in frontend dev, so this was the lowest hanging fruit I felt comfortable tackling. I do have a few other features in mind and will probably open more PRs down the line as I get more comfortable with the codebase.

One thing to be transparent about: this was written with the help of Claude, but I've personally checked the changes, made sure extra test cases were written before opening this PR, do forgive me if you find anything not up to standard.

Kind regards,

lvkoppen


Summary

URL-based sharing was broken for complex builds — the ?state= query param grew too large for browsers and servers to handle. This PR replaces it with a blueprint string system: a copy-paste code (COI1:…) that works for any build size, and adds import access from both the canvas and the start screen.

Changes

New files

  • utils/blueprint.tsencodeToBlueprintString / decodeFromBlueprintString using lz-string compression. Strips all runtime-only fields on encode (callbacks, inputs/outputs, full building objects); stores only node id, type, position, name, building id, and multiplier.
  • __tests__/utils/blueprint.test.ts — 30 unit tests covering round-trips, edge cases, runtime field stripping, hydration contract, and large build safety.
  • bunfig.toml — Scopes bun test to __tests__/ so Playwright e2e specs are no longer picked up as unit tests.
  • declarations.d.ts — Declares *.css modules to fix a TypeScript 5.8 side-effect import warning.

Modified files

  • components/ShareButton/ShareButton.tsx — Replaced "copy URL" with two buttons: export (copies blueprint string to clipboard) and import (opens paste modal).
  • pages/canvas.tsx — Removed all URL state writing. Kept ?state= reading for backward compat with old shared links. Blueprint and legacy URL imports both push state into Flow via externalState.
  • components/Flow/Flow.tsx — Added externalState prop. When its version increments, a useEffect replaces Flow's internal nodes/edges. Necessary because useNodesState/useEdgesState ignore prop changes after mount.
  • pages/index.tsx — Added "Import Blueprint" button and paste modal on the start screen. On load, navigates to /canvas?state=<blueprint>.
  • components/ObjectiveSelector/ObjectiveSelector.tsx — Added optional actionButton?: React.ReactNode prop rendered in the right header slot (previously an empty spacer), so the import button renders inside the full-screen overlay instead of behind it.
  • package.json — Added lz-string + @types/lz-string dependencies.

Commits

  • feat: blueprint string system (core encode/decode, ShareButton, canvas wiring)
  • fix: blueprint import now updates canvas + import button on start screen
  • style: JSDoc and inline prop comments per contributing guide

lvkoppen added 3 commits May 6, 2026 19:00
Flow's internal state (useNodesState/useEdgesState) ignores prop changes
after mount, so blueprint imports were silently dropped. Fixed by adding
an externalState prop with a version counter that Flow watches via
useEffect — when version increments, Flow replaces its nodes/edges.

Also added an "Import Blueprint" button to the start screen via a new
actionButton slot in ObjectiveSelector, so users can load builds without
first building a new one.

- Flow.tsx: externalState prop + useRef version tracking
- canvas.tsx: setExternalState on blueprint import and URL state load
- ObjectiveSelector.tsx: optional actionButton prop in header right slot
- index.tsx: Import Blueprint button wired to paste modal
- bunfig.toml: scope bun test to __tests__/ (exclude Playwright e2e)
- blueprint.test.ts: 3 new tests for runtime field stripping + hydration contract
Add JSDoc to exported functions in blueprint.ts and ShareButton component.
Add inline prop comments to ShareButtonProps, FlowProps, and
ObjectiveSelectorProps. Add declarations.d.ts to fix CSS side-effect
import warning introduced by TypeScript upgrade to 5.8.
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.

1 participant