Skip to content

Precompile option#245

Open
aparlato wants to merge 30 commits intomainfrom
precompile-option
Open

Precompile option#245
aparlato wants to merge 30 commits intomainfrom
precompile-option

Conversation

@aparlato
Copy link
Collaborator

@aparlato aparlato commented Oct 17, 2025

Description

Alternative to #243

More likely to work more smoothly for our needs and cover future compiling use cases.

You need to input the compilation script, so this will work for various compiling use cases if users build their own spec.

QA steps

  • Get local config from @aparlato (the only example built is from a downstream client)
  • Open the app
  • Confirm that selecting various checkbox options turns on/off the relevant features
  • Confirm that on refresh, those features/checkboxes are still selected
  • Confirm that checkboxes are all deselected on changing style (except the default)
  • Confirm non-compiled map styles work as expected

Author checklist

Create the PR

  • Fill out PR template
  • Make sure you've added a CHANGELOG entry under "Unreleased"
  • Request a review
  • Make any requested changes and get approval

After approval

  • Merge any changes from main into your branch, resolve any conflicts
  • Squash & merge changes into main
  • Delete branch

src/App.svelte Outdated
// in MapStyleInputWrapper are coming from polled styles or from history
const nextMaps = JSON.parse(JSON.stringify(maps)).map(m => {
// cloneDeep copies over functions in case those are the values
const nextMaps = _.cloneDeep(maps).map(m => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to replace all clones using JSON.parse(JSON.stringify(...)) with cloneDeep or something similar to prevent losing functions passed as values from the config.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd lean toward es-toolkit when possible, it's more modern / has a smaller footprint than lodash.

let isUrl = !style && typeof url === 'string';
let stylesheet = style;
if (isUrl) {
stylesheet = await fetchUrl(url);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think we should just do this if we need a precompile rather than always? Seems fairly quick, but maybe better to skip a fetch when possible.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think letting the map library handle the fetch / cache / etc would be good if we're not modifying the style.

@aparlato aparlato changed the title [WIP] Precompile option Precompile option Oct 22, 2025
@aparlato aparlato requested a review from ebrelsford October 22, 2025 00:05
@aparlato aparlato marked this pull request as ready for review October 22, 2025 00:05
Copy link
Contributor

@ebrelsford ebrelsford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a slightly hard time testing it, biggest thing is I think we should document it.

src/App.svelte Outdated
// in MapStyleInputWrapper are coming from polled styles or from history
const nextMaps = JSON.parse(JSON.stringify(maps)).map(m => {
// cloneDeep copies over functions in case those are the values
const nextMaps = _.cloneDeep(maps).map(m => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd lean toward es-toolkit when possible, it's more modern / has a smaller footprint than lodash.

- Shorten URLs by reducing map state kept in the hash to the minimum
- Don't set RTL text plugin if already in progress
- Add branch name to screenshots if looking at branch pattern
- Add precompile option
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also document this?

let isUrl = !style && typeof url === 'string';
let stylesheet = style;
if (isUrl) {
stylesheet = await fetchUrl(url);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes I think letting the map library handle the fetch / cache / etc would be good if we're not modifying the style.

@aparlato
Copy link
Collaborator Author

aparlato commented Oct 22, 2025

@ebrelsford ok, I believe I've gotten this sorted out now. The issue was that I wasn't compiling on first render so it was trying to handle some sources that should be stripped off inappropriately. Now it's set to use a default value on first render if a selected option isn't available.

@aparlato aparlato requested a review from ebrelsford October 22, 2025 20:16
Copy link
Contributor

@ebrelsford ebrelsford left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good! When I click a label on the right map it seems to trigger the checkbox on the left map? Presumably because currently the ids for checkboxes are reused? They appear to be simply the index of the option, but should be globally unique.

@aparlato
Copy link
Collaborator Author

Ok, I believe I have fixed everything now. I also found a bug where adding a map wasn't behaving as expected.

Now when you add a map, it will default to the virtual variant of the previous map, but maintain default value on switching the map style in that pane.

@aparlato aparlato requested a review from ebrelsford October 23, 2025 19:35
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.

2 participants